Results 1 to 7 of 7
Thread: Problems with CLASSPATH
- 03-23-2012, 10:06 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Problems with CLASSPATH
Hi,
I read with attention yr recommendation and of course it works. Normally I use Scite editor when working in java.
My program in java is very similar to that of the former inquirer and it works when using the windows md-dos console
in the way you say (java -cp "C:\....\sqlitejdbc-v056.jar";. ConnectSQLite)
But when I try to register the path of sqlitjdbc-v056.jar in the CLASSPATH environment variable and try to
run the same program through Scite, it doesnt work and gives the usual excepcion...
java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at ConnectSQLite.main(ConnectSQLite.java:23)
java.lang.NullPointerException
at ConnectSQLite.main(ConnectSQLite.java:37)
I don't know what I'm doing wrong.
Thanks in any way you could help.http://www.java-forums.org/images/smilies/skype/=(.gif
- 03-23-2012, 10:13 PM #2
Re: Problem finding SQLite JDBC driver
Please start a new thread for your problem.
Include the console contents when you post.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.If you don't understand my response, don't ignore it, ask a question.
- 03-24-2012, 01:13 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: Problem finding SQLite JDBC driver
Thanks for yr reply
This is the program:
**
* ConnectSQLite.java
*/
//package com.javaworkspace.connectsqlite;
import java.sql.*;
/**
* @author
*
*/
public class ConnectSQLite {
public static void main(String[] args) {
Connection connection = null;
ResultSet resultSet = null;
Statement statement = null;
try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager
.getConnection("jdbc:sqlite:C:\\Program Files\\Java\\jre6\\lib\\EMPLOYEE.db");
statement = connection.createStatement();
resultSet = statement
.executeQuery("SELECT EMPNAME FROM EMPLOYEEDETAILS");
while (resultSet.next()) {
System.out.println("EMPLOYEE NAME:"
+ resultSet.getString("EMPNAME"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
resultSet.close();
statement.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
The program compiles oK but when running it (on Scite editor) this is the message:
>C:\Archivos de programa\Java\jdk1.6.0_21\bin\javac ConnectSQLite.java
>Exit code: 0
>C:\Archivos de programa\Java\jdk1.6.0_21\bin\java -cp . ConnectSQLite
java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at ConnectSQLite.main(ConnectSQLite.java:20)
java.lang.NullPointerException
at ConnectSQLite.main(ConnectSQLite.java:34)
>Exit code: 0
This source java program is in directory:
C:\Users\Claudio\Desktop\PROGRAMAR\JAVA\MiProyecto
These are the CURRENT values of my system variables:
CLASSPATH:
.;C:\Program Files\Java\jdk1.6.0_21;C:\Program Files\Java\jre6\lib\sqlitejdbc-v056.jar;.;%DERBY_HOME%\lib\derby.jar;.;C:\Users\C laudio\Desktop\PROGRAMAR\JAVA\MiProyecto\SimpleApp ;.
JAVA_HOME:
C:\Program Files\Java\jre6
PATH:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShel l\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\Java\jdk1.6.0_21\bin
Many thanks in advance for your help.
(P.D.: I've never had more problems than when trying to install and use any database system in java.
I have experience in installing and using PostgreSQL but not in Java. I used it with Python.
I've installed SQLite and it works ok on console. The problem is when I try to use it in Java.
Have the same problem when try to use JavaDB).Last edited by DarrylBurke; 03-26-2012 at 01:05 PM. Reason: Removed irrelevant link
- 03-24-2012, 01:30 AM #4
Re: Problem finding SQLite JDBC driver
The java program can not find the class listed in the error message. You need to put the jar file containing that class's class file on the classpath.java.lang.ClassNotFoundException: org.sqlite.JDBC
java -cp <JARFILE>.jar;. <CLASSNAME>If you don't understand my response, don't ignore it, ask a question.
- 03-26-2012, 10:54 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Problem finding SQLite JDBC driver
To add to Norms post, do not rely on CLASSPATH.
You should always define your classpath at execution, using the -cp switch.
One reason is that CLASSPATH is the last place Java goes to find out what classpath it should use. -cp takes precedence, and the manifest in an executable jar takes precedence over that.
Another reason is that if you have mutliple projects on one box not all of them will want to use the same versions of jar files.Please do not ask for code as refusal often offends.
- 03-26-2012, 01:06 PM #6
Re: Problem finding SQLite JDBC driver
Also, next time you have a question start your own thread -- they're free. This one's tow years old.
I'm splitting the current discussion to a new thread.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-26-2012, 01:07 PM #7
Re: Problems with CLASSPATH
Split from Problem finding SQLite JDBC driver
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
ClassPath
By homka in forum New To JavaReplies: 0Last Post: 10-05-2011, 01:18 PM -
what is runtime classpath and what is designtime classpath?
By LongTTH in forum New To JavaReplies: 1Last Post: 05-03-2011, 02:28 AM -
Classpath
By Parneel in forum Enterprise JavaBeans (EJB)Replies: 4Last Post: 04-01-2009, 12:22 PM -
Classpath on mac osx
By jacobb in forum JDBCReplies: 0Last Post: 06-12-2008, 09:41 PM -
Set classPath?
By rgbosque in forum New To JavaReplies: 3Last Post: 02-07-2008, 02:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks