Originally posted by smitha rai:
Hi,
I am getting the following errror for my code.
JDBCMsAccessConnection.java:23: catch not reached.
} catch(ClassNotFoundException e) {
^
JDBCMsAccessConnection.java:27: catch not reached.
} catch(SQLException sqlex) {
^
JDBCMsAccessConnection.java:68: catch not reached.
} catch(ClassNotFoundException e) {
^
JDBCMsAccessConnection.java:71: catch not reached.
} catch(SQLException sqlex) {
^
4 errors
Can any one suggest me, where is my mistake?
Thanks
Smitha
==========================================
My code is :
package DatabaseConnection;
import java.sql.*;
class JDBCMsAccessConnection {
protected static Connection getAccessConnection() throws Exception {
String url = "jdbcdbc:data";
String uid = "";
String pwd = "";
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection (url,uid,pwd);
} catch(Exception e) {
System.err.print("Exception: Occurred while Establishing Connection ---> method getAccessConnection() " + e);
System.err.println(e.getMessage());
throw e;
} catch(ClassNotFoundException e) {
System.err.print("ClassNotFoundException: Occurred while Establishing Connection ---> method getAccessConnection() " + e);
System.err.println(e.getMessage());
throw e;
} catch(SQLException sqlex) {
System.err.print("Exception: Occurred while performing Database Operations ---> method getAccessConnection() " + sqlex);
System.err.println(sqlex.getMessage());
throw sqlex;
}
return conn;
}
protected void closeAll(Statement stmt, ResultSet rs, Connection conn) {
try {
stmt.close();
rs.close();
conn.close();
} catch(SQLException e){
System.out.println("Exception Occurred while Closing ---> method closeAll() " + e);
}
}
public static void main (String args[]) {
JDBCMsAccessConnection joc = new JDBCMsAccessConnection();
try {
Connection con = joc.getAccessConnection();
Statement stmt = con.createStatement ();
String query = "Select * from coffees";
ResultSet rs = stmt.executeQuery (query);
while (rs.next()) {
System.out.println(rs.getString("cofname") + " " + rs.getInt(2) + " " +
rs.getFloat(3)+ " " + rs.getInt(4) + " " + rs.getInt(5));
} // ** End of While
joc.closeAll();
} catch(Exception e) {
System.err.print("Exception: Occurred while Establishing Connection ---> method Main() " + e);
System.err.println(e.getMessage());
} catch(ClassNotFoundException e) {
System.err.print("ClassNotFoundException: Occurred while Establishing Connection ---> method getAccessConnection() " + e);
System.err.println(e.getMessage());
} catch(SQLException sqlex) {
System.err.print("Exception: Occurred while performing Database Operations ---> method Main() " + sqlex);
System.err.println(sqlex.getMessage());
}
} // ** End of Main
} // ** End of Class
Love you Hamesha
Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Consider Paul's rocket mass heater. |