我正在尝试使用 JDBC 从表中获取所有列值。
这是我在主程序中编写的代码。
Class.forName( "com.mysql.jdbc.driver" );
String url = "jdbc:jtds:sqlserver://test.com/abc_1_20121225;instance=abcd";
Connection conn = DriverManager.getConnection(url,"uname","pwd");
Statement stmt = conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT table_name, column_name, data_type, data_length FROM USER_TAB_COLUMNS WHERE table_name = 'MyTable'");
while ( rs.next() ) {
String colName = rs.getString("column_name");
System.out.println(colName);
}
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
我在我的类路径中添加了 jtds.jar。我收到这条消息
Got an exception!
com.mysql.jdbc.driver
有人可以告诉我问题的确切原因吗?
编辑:
添加 stactrace;
java.lang.ClassNotFoundException: com.mysql.jdbc.driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at schwab.TestDB.main(TestDB.java:15)