Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

asteriod

Greenhorn
+ Follow
since Jul 03, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by asteriod

Originally posted by Rahul Mahindrakar:
[B]section 8.1.2 of the JLS version 2.0 specifies that the
ClassModifier can only be one of
public abstract final
so the matter is closed as to whether classes can be synchronized. Classes cannot be synchronized.
reply by Asteriod :
Classes can be synchronized.

example

public synchronized class HttpPresentationComms {
// fields
public final HttpPresentationRequest request;
public final HttpPresentationResponse response;
public final Application application;
public Session session;
public SessionData sessionData;
public Throwable exception;
public XMLCFactory xmlcFactory;
protected HttpPresentationComms(HttpPresentationRequest p0, HttpPresentationResponse p1, Application p2) {
// CONSTRUCTOR
}
}
Synchronized classes are those whose methods are protected from concurrent invocation of their methods

Hi ! Smitha ,
Just remove the stuff shown below in your code.
catch(Exception e) {
System.err.print("Exception: Occurred while Establishing Connection ---> method Main() " + e);
System.err.println(e.getMessage());
}

Because all exceptions will be first handled by this handler and
more specific handlers willnot get a chance to catch the more specific handlers listed below.

Hope this will help .
Dayanand

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 = "jdbc dbc: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