Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 java sql connectivity

Author  Topic 

computechsys
Starting Member

1 Post

Posted - 2008-05-06 : 16:06:47
hey guys, im trying to create a simple java program that utilizes an sql database. I believe i have the right drivers installed, it shows me the Java DB(Network and Embedded) in my NetBeans Database section and I can see the databases. I can connect to the database by right clicking and hitting connect, but I am having a really tough time connecting through java. I've gone in and set Java DB installation and database location and even set up a JavaDBEmbedded classpath in the library manager. I also installed a file of derby.jar in every one of the folders that the project is in because i heard it needed to be in one of them.

When I run the code i throw an exception, but i dont know what it is that I'm doing wrong to throw it. I have a feeling it might be my set up of derby or something to do with environment variables, yet i can connect easily through netbeans and can even let it create a predfined database application (doesn't quite do what i need).

Please help, im getting desperate!!!

import java.sql.*;
public class Main {
public static void main(String[] args) {
try {
//driver name taken from java DB(Embedded) properties in NetBeans databases
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
//url taken from wanted database properties url
String url = "jdbc:derby://localhost:1527/sqlTest";
Connection conn = DriverManager.getConnection(url, "root", "admin");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Produces the following errors:

init:
deps-jar:
compile:
run:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at sqltests.Main.main(Main.java:18)
BUILD SUCCESSFUL (total time: 0 seconds)

What am I doing wrong??
   

- Advertisement -