Thank you for this reply but I'm currently working under Linux with version 1.5.0_15 of
the JDK, well maybe my classpath variable is not correctly set; it is set as:
/usr/share/jdbc/mysql-connector-java-5.1.6-bin.jar:/usr/share/tomcat/apache-tomcat-6.0.18/lib/servlet-api.jar
Something is missing?? I don't know equivalent of \jarfiles\log4j-1.2.8.jar under Linux
Thank you for suggestions
Regards
Michel
On 4/19/09, Douglas Nelson <Douglas.Nelson@stripped> wrote:
> This is the classpath I set:
>
>
> classpath=.;c:\;c:\download\java\commons-logging-1.0.4.jar;c:\jarfiles\log4j-1.2.8.jar;c:\jarfiles\mysql-connector-java-5.1.5-bin.jar;
>
> this is the code I use to connect to a MySql database
> //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> // start getConnection
> //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> /**
> * Creates a new connection to the database
> * @return the connection object
> */
> private Connection getConnection() throws Exception{
> logger.info("getConnection called");
> //------------------------
> // Load up the jdbc driver
> //------------------------
> try {
> Class.forName("com.mysql.jdbc.Driver").newInstance();
> } // end try
> catch (Exception any) {
> logger.error("Unable to load driver. [" + any.getMessage() + "]");
> throw(any);
> } // end catch
>
> return(DriverManager.getConnection("jdbc:mysql://" + mysql_host +
> ":" + mysql_port +"/" + mysql_database + "?user=" + mysql_user +
> "&password=" + mysql_password));
>
> } // end getConnection
>
>
>
> Michel Maria-Sube wrote:
>> hello,
>>
>> I'm working on an application connecting with mysql5, considering that
>> $CLASSPATH is correctly set and piece of code for connection is as
>> follows:
>>
>> public void connectDB( String DBname, String user, String passwd ) {
>> java.sql.Connection conn = null;
>> String url = null;
>>
>> try {
>> Class.forName("com.mysql.jdbc.Driver").newInstance();
>> }
>> catch (ClassNotFoundException cnfe) {
>> System.out.println("\nClassNotFoundException occured");
>> System.out.println("connection with the DB is not possible");
>> cnfe.printStackTrace();
>> System.exit(ERROR);
>> }
>> catch (InstantiationException ie) {
>> System.out.println("InstantiationException occured");
>> System.out.println("connection with the DB is not possible");
>> System.exit(ERROR);
>> }
>> catch (IllegalAccessException iae) {
>> System.out.println("IllegalAccessException occured");
>> System.out.println("connection with the DB is not possible");
>> System.exit(ERROR);
>> }
>> try {
>> url = new
>> String("jdbc:mysql://localhost/"+DBname+"?user="+user+"&password="+passwd);
>> .......................
>>
>> Execution gives following exception:
>>
>> ClassNotFoundException occured
>> connection with the DB is not possible
>> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
>> 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:276)
>> 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:169)
>> at MainFrame.connectDB(MainFrame.java:290)
>> at MainFrame.createMainScreen(MainFrame.java:260)
>> at MainFrame.<init>(MainFrame.java:68)
>> at MainFrame.main(MainFrame.java:1049)
>>
>> This behavior disapears if I update the jar archive for executable with
>> classes content in the jdbc archive but of course I don't want to do that;
>> does anybody could indicate me why java is anable to solve correctly paths
>> in the jdbc archive?
>>
>> Thank you in advance
>> Regards
>> M.
| Thread |
|---|
| • Re: solving paths on the jdbc archive | Michel Maria-Sube | 17 Jun 2009 |