Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java JDBC Apache path
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");
 
// THIS IS WHERE IT ALL DIES ON ME
    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 Smile | :) ? 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...:(
Posted 2-Jul-12 2:09am
dsagner240
Edited 2-Jul-12 9:17am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I havent given a shot but I think this is what the problem might be. You havnt specified Username and Password in connection string.
So the connection string would be something like this:
"jdbc:derby://localhost:1527/Lesson22;user=me;password=mine";
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 646
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,158
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100