Results 1 to 5 of 5
- 09-28-2009, 08:03 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 22
- Rep Power
- 0
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:
the second class which call that constructor 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 {...
thank you for your kind help in this matter... TIA.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 {
- 09-28-2009, 09:00 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Do an e.printStackTrace() of the exception that you got and post the results.
- 09-28-2009, 09:30 PM #3
Member
- Join Date
- Sep 2009
- Posts
- 22
- Rep Power
- 0
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); }
- 09-28-2009, 09:51 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 09-29-2009, 02:32 PM #5
Member
- Join Date
- Sep 2009
- Posts
- 22
- Rep Power
- 0
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:
The methods contains in JDBCTableModel....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..
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
-
java.sql.SQLException: No suitable driver
By Heather in forum JDBCReplies: 6Last Post: 09-01-2010, 11:29 AM -
unreported exception IOException -- Yet I AM catching it?
By Agathorn in forum New To JavaReplies: 2Last Post: 09-18-2009, 11:22 PM -
java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]System Exception: Connection
By Ram_TPS in forum JDBCReplies: 1Last Post: 10-16-2008, 02:09 PM -
Error: unreported exception java.io.IOException; ??
By jonsamwell in forum New To JavaReplies: 5Last Post: 08-24-2008, 04:11 AM -
SQLException: Unable to connect to any hosts due to exception
By simon in forum JDBCReplies: 1Last Post: 07-23-2007, 11:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks