sabrinam03
Messages postés7Date d'inscriptionvendredi 14 mars 2008StatutMembreDernière intervention19 avril 2008
-
5 avril 2008 à 16:12
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013
-
5 avril 2008 à 18:23
salut, aprés avoir installé MySQL et tous ce qui est nécessaire ,j'arrive pas à connecter à ma base , je crois que le pb est que je n'ai pas installé le driver et je ne sais pas comment,
svp quelqu'un peut me dire comment.et merci d'avance
voici mon code
import java.sql.*;
public class MonClasse {
public static void main(String args[]) {
// ---- configure this for your site
String username = "root";
String password = "root";
// The URL that will connect to TECFA’ MySQL server
// Syntax: jdbc:TYPE:machine:port/DB_NAME
String url = "jdbc:mysql://localhost:3306/base1";
// A canned query string
String queryString = "SELECT abv, def FROM base1.defabv";
// ---- configure END
// INSTALL/load the Driver (Vendor specific Code)
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
Connection con;
Statement stmt;
// Connection to the database at URL with usename and password
con = DriverManager.getConnection(url,username,password);
System.out.println ("Ok, connection to the DB worked.");
System.out.println ("Let’ see can retrieve something with: " +
queryString);
// Create a Statement Object
stmt = con.createStatement();
// Send the query and bind to the result set
ResultSet rs = (ResultSet) stmt.executeQuery(queryString);
while (rs.next()) {
String s = rs.getString("abv");
String n = rs.getString("def");
System.out.println(s + " " + n);
}
// Close resources
stmt.close();
con.close();
}
// print out decent error messages
catch(SQLException ex) {
System.err.println("==> SQLException: ");
while (ex != null) {
System.out.println("Message: " + ex.getMessage ());
System.out.println("SQLState: " + ex.getSQLState ());
System.out.println("ErrorCode: " + ex.getErrorCode ());
ex = ex.getNextException();
System.out.println("");
}
}
}
}
l'erreur est:
ClassNotFoundException: com.mysql.jdbc.Driver
> SQLException:
Message: No suitable driver found for jdbc:mysql://localhost:3306/base1
SQLState: 08001
ErrorCode: 0
cs_DARKSIDIOUS
Messages postés15814Date d'inscriptionjeudi 8 août 2002StatutMembreDernière intervention 4 mars 2013129 5 avril 2008 à 18:23
Salut,
Il te suffit de le référencer dans les libraries utilisées par le jar de ton application (dans le fichier MANIFEST)
______________________________________
DarK Sidious