You are not logged in.

#1 2014-01-10 21:51:37

otto88
Member
Registered: 2012-12-16
Posts: 74

JDBC and MySQL doesn't work

i've followed th wiki
https://wiki.archlinux.org/index.php/JDBC_and_MySQL

but when i do java DBDemo
this is the output:

java DBDemo 
com.mysql.jdbc.Driver
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at DBDemo.main(DBDemo.java:18)

instead when i tried

@arch mysql-connector-java-5.1.28]$ sudo  x=mysql-connector-java-mysql-connector-java-5.1.28-bin.jar; install -D $x /opt/java/jre/lib/ext/${x##*/}

output:

@arch mysql-connector-java-5.1.28]$ sudo  x=mysql-connector-java-mysql-connector-java-5.1.28-bin.jar; install -D $x /opt/java/jre/lib/ext/${x##*/} 
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...
install: missing destination file operand after '/opt/java/jre/lib/ext/'
Try 'install --help' for more information.

Last edited by otto88 (2014-01-10 21:53:14)

Offline

#2 2014-01-11 09:39:20

otto88
Member
Registered: 2012-12-16
Posts: 74

Re: JDBC and MySQL doesn't work

please, is urgent

Offline

#3 2014-01-11 09:48:24

aaditya
Member
Registered: 2013-09-01
Posts: 174

Re: JDBC and MySQL doesn't work

sudo  x=mysql-connector-java-mysql-connector-java-5.1.28-bin.jar; install -D $x /opt/java/jre/lib/ext/${x##*/}

su
# x=mysql-connector-java-*-bin.jar; install -D $x /opt/java/jre/lib/ext/${x##*/}

https://wiki.archlinux.org/index.php/Sudo

Offline

#4 2014-01-11 20:27:36

otto88
Member
Registered: 2012-12-16
Posts: 74

Re: JDBC and MySQL doesn't work

thanks, ok i've done but this is the output:


@arch ~]$ java DBDemo
com.mysql.jdbc.Driver
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at DBDemo.main(DBDemo.java:18)

Offline

#5 2014-01-12 21:09:07

otto88
Member
Registered: 2012-12-16
Posts: 74

Re: JDBC and MySQL doesn't work

what can i try to fix it ?

Offline

#6 2014-01-31 00:20:48

edward
Member
From: Baton Rouge, Louisiana, USA
Registered: 2014-01-30
Posts: 2

Re: JDBC and MySQL doesn't work

I'm not sure if this is too late to help you, but you might try adding /opt/java/jre/lib/ext/ to your classpath. You can do this temporarily by invoking your test program like this:

java -classpath ".:/opt/java/jre/lib/ext/mysql-connector-java-mysql-connector-java-5.1.28-bin.jar" DBDemo

. The problem is that your Java Runtime Environment can't find the JDBC driver, probably because it doesn't know to look for it in the directory where you installed it, but you can tell it where to look using the -classpath option. Just don't forget to tell it also to look in ".", that is, the current working directory, because otherwise it won't find DBDemo.class.

Offline

#7 2014-02-02 12:49:15

otto88
Member
Registered: 2012-12-16
Posts: 74

Re: JDBC and MySQL doesn't work

edward wrote:

I'm not sure if this is too late to help you, but you might try adding /opt/java/jre/lib/ext/ to your classpath. You can do this temporarily by invoking your test program like this:

java -classpath ".:/opt/java/jre/lib/ext/mysql-connector-java-mysql-connector-java-5.1.28-bin.jar" DBDemo

. The problem is that your Java Runtime Environment can't find the JDBC driver, probably because it doesn't know to look for it in the directory where you installed it, but you can tell it where to look using the -classpath option. Just don't forget to tell it also to look in ".", that is, the current working directory, because otherwise it won't find DBDemo.class.

i try to run

java -classpath ".:/dati/Documenti/-INGSW2/mysql-connector-java-5.1.26" DBDemo
com.mysql.jdbc.Driver
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:190)
        at DBDemo.main(DBDemo.java:18)

Offline

#8 2014-02-02 18:43:45

edward
Member
From: Baton Rouge, Louisiana, USA
Registered: 2014-01-30
Posts: 2

Re: JDBC and MySQL doesn't work

otto88 wrote:
java -classpath ".:/dati/Documenti/-INGSW2/mysql-connector-java-5.1.26" DBDemo

Did you unpack the jar archive? If you still have the mysql-connector-java.5.1.26-bin.jar file, you can include the original .jar file itself in the classpath, as opposed to the directory. The important concept is that "ClassNotFoundException" means that the class you want to use is not in your classpath, which means you either need to change the classpath to point to a place that has the class, or put the class into your classpath.

Offline

Board footer

Powered by FluxBB