Jump to content

Unable to display the table


aristal

Recommended Posts

This is my code:import java.net.URL;import java.sql.*;import java.lang.String;import java.lang.StringBuffer;import java.sql.Connection;public class SQLQuery{ public static void main (String argv[]) { //SQLQueryFormat a = new SQLQueryFormat(); System.out.println("\nEstablishing Connection - Pls Wait... \n"); try { //Connect to the database specified in the URL Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:EG1"); System.out.println("Connection Established.\n"); //Create a SELECT statement object Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); //Issue the SELECT statement String querySt = "SELECT PRT_REF_NO, PRT_DESCR, SPT_IN_STOCK, SPT_CONTROL, SPT_PRICE, SPT_DESCR " + "FROM Parts, SupplierPartLink " + "WHERE PRT_ID = SPT_PRT_ID " + "AND SPT_SUP_ID=1 " + "ORDER BY PRT_REF_NO "; ResultSet res = stmt.executeQuery(querySt); //For each row retrived from the select statement System.out.println("Retriving results for MCK\n"); System.out.println("part Description\t\t Stock\t Control Level\t Price"); System.out.println("---- -----------\t\t -----\t -------------\t -----\n"); while (res.next()) { //Retrieve each column in the row String ref = res.getString("PRT_REF_NO"); //PRT_REF_NO System.out.println(" " + ref); String desc= res.getString(2); //PRT_DESC System.out.println(" " + desc); int stk= res.getInt(3); //SPT_IN_STOCK System.out.println(" " + stk); int ctrl = res.getInt(4); //SPT_CONTROL System.out.println(" " + ctrl); String cost= res.getString(5);//SPT_PRICE System.out.println(" " + cost); } //Close Statement and Connection stmt.close(); con.close(); System.out.println("\nConnection Closed - Operation Successful."); } catch(Exception E) { //Print out the Exception Error System.out.println("Error:" +E ); } } }The prob is that i am unable to display ....System.out.println(" " + ref);....System.out.println(" " + desc); ...System.out.println(" " + stk); ...System.out.println(" " + ctrl); and System.out.println(" " + cost);I have no problem displaying the rest. Can any one offer me some advise on what could have gone wrong?Thanks

Link to comment
Share on other sites

The prob is that i am unable to display ....System.out.println(" " + ref);....
This actually looks more like a Java problem, so you may not get an answer here in the SQL forum. Suggest you post your problem to a Java forum, including what "unable to display" means. For instance do you see a blank line, or does an error occur, etc. Hope this helps.
Link to comment
Share on other sites

Also make sure that the query is actually returning data and not an empty result set. If you're issuing a query to the database, getting a result set, and printing it but nothing prints, then the result set is probably empty.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...