Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:


Java
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 :)? THANKS!

//EDIT:::::::

Think I have somehow found out that I am missing the
C#
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
Updated 2-Jul-12 9:17am
v2

1 solution

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";
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900