Results 1 to 5 of 5
  1. #1
    javamula is offline Member
    Join Date
    Sep 2009
    Posts
    22
    Rep Power
    0

    Default Unreported exception java.sql.SQLException

    Dear All,
    Please guide further, why i get the above message.

    the first class is JDBCTableModel. The Constructor code as follows:

    Java Code:
    public JDBCTableModel (Connection conn,
    				   String tableName)
    			throws SQLException {
    			super();
    			getTableContents (conn, tableName);
                           	}
    		protected void getTableContents (Connection conn,
    					 String tableName)
    			throws SQLException {...
    the second class which call that constructor as follows:

    Java Code:
    try{
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            } catch (ClassNotFoundException e) {
            throw new SQLException("Unable to load driver class"); }
            connect = DriverManager.getConnection("jdbc:derby://localhost:1527/IP","A","acf");
            String tableCode = "Module";
            JDBCTableModel tablemodel = new JDBCTableModel(connect,tableCode) throws SQLException {
    thank you for your kind help in this matter... TIA.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Do an e.printStackTrace() of the exception that you got and post the results.

  3. #3
    javamula is offline Member
    Join Date
    Sep 2009
    Posts
    22
    Rep Power
    0

    Default

    Dear r035198x,

    thank you for the guidance, i have modified the code in the second class per your advice. so NO more SQLException. But please guide further why variable "jtable" unrecognized?

    the second class modification:
    Java Code:
    JDBCTableModel tablemodel;
    Connection dbConnect;
            try {
            ConnectionJDBC cj4 = new ConnectionJDBC(); 
            dbConnect= cj4.makeConnection(); ///create the third new class see the excerpt code below.
            String tableCode = "Module";
            tablemodel = new JDBCTableModel(dbConnect,tableCode);
            JTable jtable = new JTable(tablemodel);
            }
            catch ( SQLException sqlex ) {
             // process SQLExceptions here
             sqlex.printStackTrace();
             System.out.println("Connection unsuccessful\n" +sqlex.toString() );
             }
    
    int c= jtable.getColumnCount(); ////[COLOR="Red"]Unrecognized variable jtable[/COLOR]
    int r = jtable.getRowCount(); /////////[COLOR="Red"]Unrecognized variable jtable[/COLOR]

    the third class code:
    Java Code:
    private static String driver = "org.apache.derby.jdbc.ClientDriver";
    private static String url = "jdbc:derby://localhost:1527/IP";
    private static String sso = "A";
    private static String pw = "acf";
        
    public Connection makeConnection()
    throws SQLException {
    try {
    Class.forName(driver);
    } catch (ClassNotFoundException e) {
    throw new SQLException("Unable to load driver class"); }
    return DriverManager.getConnection(url, sso, pw);
    }

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    It's declared inside the try block and so is out of scope when the try block ends.
    You should read Sun's tutorial to learn the basic scoping rules before trying to write Swing and JDBC programs.

  5. #5
    javamula is offline Member
    Join Date
    Sep 2009
    Posts
    22
    Rep Power
    0

    Default

    Dear r035198x,

    thank you for the guidance...case close about the SQLException by now..

    but now new problem arise...the jtable in not displayed in the scrollpane...
    here is the excerpt code:

    Java Code:
    Connection conn = cj.makeConnection();
    String tableName = createSampleTable(conn); ///Return the tableName
                TableModel tablemodel = new JDBCTableModel(conn, tableName);
                JTable jtable = new JTable(tablemodel);
                jtable = new JTable(tablemodel);
                int c = jtable.getColumnCount(); // got 0(Zero) instead of 3 columns why?
                int r = jtable.getRowCount(); //result correctly contains 20records..
    The methods contains in JDBCTableModel....

    Java Code:
    public int getRowCount() {
    		return contents.length;
    }
    
    public int getColumnCount() {
    		if (contents.length == 0)
    			return 0;
                    //return 8;
    		else
    			//return contents[0].length;
                    //return 10;
                    return columnNames.length;
    }

Similar Threads

  1. Replies: 6
    Last Post: 09-01-2010, 11:29 AM
  2. Replies: 2
    Last Post: 09-18-2009, 11:22 PM
  3. Replies: 1
    Last Post: 10-16-2008, 02:09 PM
  4. Error: unreported exception java.io.IOException; ??
    By jonsamwell in forum New To Java
    Replies: 5
    Last Post: 08-24-2008, 04:11 AM
  5. Replies: 1
    Last Post: 07-23-2007, 11:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •