Sto tentando di fare una connessione con Java ad un database mysql.
Mi è stato detto di usare questo driver: mysql-connector-java-3.0.8-stable-bin
E che da shell di linux devo dare questo comando:
# export CLASSPATH='.:/<percorso>/mysql-connector-java-3.0.8-stable-bin.jar'
Prima di avviare il mio programma.
Premettendo che su linux non ci sono riuscito, cosa devo fare su windows per ottenere lo stesso risultato?
Allego il codice da usare per connettersi al database:
(l'errore che mi da come risultato ovviamente è NoClassDefFoundError)
[..]
try {
// Load the Mysql JDBC driver
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e) {
System.out.println ("Mysql device driver does not exist");
System.exit(1);
}
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/<db>?user=<user>&password=<pass>");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from content");
rset.next();
[..]