Hello to all,
Since I am very new to the community, I hope you will excuse my automatic question writing (can't seem to find an adequate answer).
I am learning about JDBC, and ran against a wall in start. I managed to set up an example DB, called Lesson22, and added a table Employee with 3 rows of data.
Now, in my main java project using eclipse IDE i wrote something like this:
package com.rvs.JavaI.JDBC;
import java.sql.*;
public class MainClass {
public static void main(String argv[])
{
Connection conn = null;
Statement stmt = null;
ResultSet rset= null;
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
conn = DriverManager.getConnection("jdbc:derby://localhost:1527/Lesson22");
String query = "SELECT * from Employee";
stmt = conn.createStatement();
rset = stmt.executeQuery(query);
while(rset.next())
{
int empNo = rset.getInt("EMPNO");
String eName = rset.getString("ENAME");
String job = rset.getString("JOB_TITLE");
System.out.println("" + empNo + ", " + eName + ", " + job);
}
}
catch (SQLException se) {
System.out.println("SQLError: " + se.getMessage() + " code: " + se.getErrorCode());
}
catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
finally {
try {
rset.close();
stmt.close();
conn.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
The thing is I have seen a comment on that line, and it said that I can skip this line if using Derby, but derbyclient.jar has to be included into the CLASSPATH variable.
Read it, done it, i think at least...
Commenting the line that spills the drink makes the app bust out on the last try{}catch{} block, where I attempt to free used system resources. The console output after commenting the Class.forName() line:
SQLError: No suitable driver found for jdbc:derby://localhost:1527/Lesson22 code: 0
And with the Class.forName() line:
org.apache.derby.jdbc.ClientDriver
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
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 com.rvs.JavaI.JDBC.MainClass.main(MainClass.java:14)
Where's the catch? What did I do wrong? No doubt I messed up, but can anyone explain to me WHAT I did :)? THANKS!
//EDIT:::::::
Think I have somehow found out that I am missing the
this ClassNotFoundException (id=37)
arg0 "org.apache.derby.jdbc.EmbeddedDriver" (id=38)
Derby drivers...or am I wrong? Thank you for the answer, but no...it's not that...:(