Où est le driver java_mysql
Bonjour,
Je viens de télécharger mysql-connector-java-5.0.5 dans mon directory "Downloads".
puis avec Terminal.app :
mv /Downloads/mysql-connector-java-5.0.5-bin.jar /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/
pour déplacer le driver.
avec un sudo pico /private/etc/profile
j'ai ajouté la ligne:
export set CLASSPATH=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/mysql-connector-java-5.0.5-bin.jar:$CLASSPATH
(voir vers la fin)
Et mon programme est le suivant :
___ beg code Test_JavaMySQL.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
//
// Test_JavaMySQL.java
// Test_JavaMySQL
//
// Created by der on 02/04/07.
// Copyright (c) 2007 __MyCompanyName__. All rights reserved.
// A simple Java applet
//
//
// import java.applet.Applet;
import java.awt.*;
import java.applet.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.*;
public class Test_JavaMySQL extends JApplet {
final String newline = System.getProperty("line.separator");
static final String helloworld = "Hello World!";
private Font font = new Font("serif", 1, 14);
final boolean DEBUG = true;
String message = "";
public void init() {//main(String[] args) {
// set the default look and feel
String laf = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(laf);
} catch (UnsupportedLookAndFeelException exc) {
System.err.println ("Warning: UnsupportedLookAndFeel: " + laf);
} catch (Exception exc) {
System.err.println ("Error loading " + laf + ": " + exc);
}
getContentPane().setLayout (null);
Connection conn = null;
try { // try_1
Class.forName("com.mysql.jdbc.Driver").newInstance(); // The newInstance() call is a work around for some
// broken Java implementations
} catch (Exception ex) { // for try_1
// handle the error
message += "47 No driver: " + ex.getMessage() + newline;
System.err.println (message);
}
//System.out.println("53 Message: " + message);
try { // try_2
conn =
DriverManager.getConnection("jdbc:mysql://localhost/test?" +
"user=root&password=");
// Do something with the Connection
if(!conn.isClosed()) {
String message = "Connected";
if (DEBUG) {
System.out.println("54 Message: " + message);
}
}
else {
message = "Not connected...";
System.out.println("Not connected...");
}
} catch (SQLException ex) { // for try_2
// handle any errors
System.err.println ("69 SQLException: " + ex.getMessage());
System.err.println ("SQLState: " + ex.getSQLState());
System.err.println ("VendorError: " + ex.getErrorCode());
}
}
//System.out.println("Message: " + message);
//if (!message <> "") {
//message = "The name of this class is: " + Test_JavaMySQL.class.getName() + ".class" + newline + message;
//}
public void paint (Graphics g) {
super.paint(g);
g.setColor(Color.red);
g.setFont(font);
g.drawString(message, 40, 80);
}
} |
___ end_code
Je compile le tout avec XCode = ok
A l'éxécution, j'ai le message suivant :
"47 No driver: com.mysql.jdbc.Driver"
et un beau message tout en rouge avec le même truc dans Safari...
Pas de driver trouvé...
Donc une erreur de déclaration de CLASSPATH ?
Ou faut-il que je mette le driver et comment le déclarer ?
Je suis allé sur http://dev.mysql.com/doc/refman/5.0/...classpath.html
et j'ai suivi pas à pas les instructions...
Merci pour un coup de main.