I built a small program for the teachers at our school and it needs to access a MySQL database. Everything was fine until I packed the class files into a jar file and tried to run it using the java -jar command and I got a "java.sql.SQLException: No suitable driver" error. The jar file sits in the same directory as the class files from which they were derived.
Here is the code:
Connection con;
public Connection getConnection() {
try{
Class.forName("com.mysql.jdbc.Driver"
.newInstance();
}catch(Exception e) {System.out.println("Std_Connection.init>no drivers"
;}
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/Standards"
;
}catch(SQLException sqle) {System.out.println("Std_Connection.init>Cannot make connection. sqle= "+sqle);}
return con;
Am I missing something?
Roy from Iowa
Here is the code:
Connection con;
public Connection getConnection() {
try{
Class.forName("com.mysql.jdbc.Driver"
}catch(Exception e) {System.out.println("Std_Connection.init>no drivers"
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/Standards"
}catch(SQLException sqle) {System.out.println("Std_Connection.init>Cannot make connection. sqle= "+sqle);}
return con;
Am I missing something?
Roy from Iowa