I am trying to get all the column values from a Table using JDBC.
This is the code that I wrote in my main program.
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());
I have added jtds.jar in my class path. I am getting this message
Got an exception!
com.mysql.jdbc.driver
Can someone tell me the exact reason for the problem?
Edit:
Adding 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)
You’re loading the wrong driver.
Replace this:
With