Unable to load database driver
Details: java.sql.SQLException: No suitable driver
This is an error I am getting after trying to make a database connection
with java to a access database. I added my database to the odbc system dsn.
I add the URL as an argument e.g java makeConnection myDatabase
I have read about 50 posts on this subject, i think i might be not
setting up the odbc system dsn right or sommat. I don't have to have a
third party driver do I.
Any help would be great.
Thanks
My code:
import java.net.URL;
import java.sql.*;
import sun.jdbc.odbc.*;
public class makeConnection {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("java MyDB <url>");
System.exit(1);
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(args[0]);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT FirstName,
LastName,Age FROM Table1");
while(rs.next()) {
String FirstName = rs.getString("FirstName");
String LastName = rs.getString("LastName");
int Age = rs.getInt("Age");
System.out.println(FirstName + " " + LastName + " " + Age);
}
stmt.close();
con.close();
}
catch (Exception x) {
}
System.err.println ("Unable to load database driver");
System.err.println ("Details : " + cnfe);
System.exit(0);
}
}
}
}
duxbuz - 26 Sep 2004 10:58 GMT
> Unable to load database driver
> Details: java.sql.SQLException: No suitable driver
[quoted text clipped - 49 lines]
> }
> }
Sorry I found solution, was not passing full argument:
was trying ---> c:\>java makeConnection myDatabase
should be ---> c:\>java makeConnection jdbc:odbc:myDatabase#
Works great now!