Connection JAVA avec MySQL
Fermé
cool-abdoul
Messages postés
96
Date d'inscription
dimanche 14 juin 2009
Statut
Membre
Dernière intervention
30 novembre 2010
-
27 oct. 2009 à 12:40
cool-abdoul Messages postés 96 Date d'inscription dimanche 14 juin 2009 Statut Membre Dernière intervention 30 novembre 2010 - 27 oct. 2009 à 15:23
cool-abdoul Messages postés 96 Date d'inscription dimanche 14 juin 2009 Statut Membre Dernière intervention 30 novembre 2010 - 27 oct. 2009 à 15:23
A voir également:
- Connection JAVA avec MySQL
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Gmail connection - Guide
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
4 réponses
cool-abdoul
Messages postés
96
Date d'inscription
dimanche 14 juin 2009
Statut
Membre
Dernière intervention
30 novembre 2010
9
27 oct. 2009 à 14:13
27 oct. 2009 à 14:13
au secours les amis !!
scriptiz
Messages postés
1424
Date d'inscription
dimanche 21 décembre 2008
Statut
Membre
Dernière intervention
14 septembre 2023
425
27 oct. 2009 à 12:41
27 oct. 2009 à 12:41
Regarde comment faire à cet endroit :
https://www.heimetli.ch/jdbc/JDBCQuery.html
https://www.heimetli.ch/jdbc/JDBCQuery.html
cool-abdoul
Messages postés
96
Date d'inscription
dimanche 14 juin 2009
Statut
Membre
Dernière intervention
30 novembre 2010
9
27 oct. 2009 à 13:57
27 oct. 2009 à 13:57
Merci de me repondre, j'ai fait le test du lien mais j'ai ce message :
class sun.jdbc.odbc.JdbcOdbcDriver
Exception in thread "main" java.lang.NullPointerException
at com.NewClass.main(NewClass.java:46)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
A mon avis , c'est là que ça coince : con = (Connection) DriverManager.getConnection(url);
voici mon code modifié :
package com;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
//import com.sun.jndi.ldap.Connection;
//import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author acoul
*/
public class NewClass {
public static void main (String [] args) throws ClassNotFoundException, SQLException{
Connection con = null ;
Statement sta = null ;
ResultSet result = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:formation_stagiare";
con = (Connection) DriverManager.getConnection(url);
sta = (Statement) con.createStatement();
String requete = "SELECT description,titre_cours FROM cours ORDER BY titre_cours";
result = sta.executeQuery(requete);
while (result.next()) {
System.out.println(result.getString(1)+" --- "+ result.getString(2));
}
} catch(SQLException s){
s.getMessage();
}
finally {
result.close() ;
sta.close() ;
con.close() ;
}
}
}
class sun.jdbc.odbc.JdbcOdbcDriver
Exception in thread "main" java.lang.NullPointerException
at com.NewClass.main(NewClass.java:46)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
A mon avis , c'est là que ça coince : con = (Connection) DriverManager.getConnection(url);
voici mon code modifié :
package com;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
//import com.sun.jndi.ldap.Connection;
//import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author acoul
*/
public class NewClass {
public static void main (String [] args) throws ClassNotFoundException, SQLException{
Connection con = null ;
Statement sta = null ;
ResultSet result = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:formation_stagiare";
con = (Connection) DriverManager.getConnection(url);
sta = (Statement) con.createStatement();
String requete = "SELECT description,titre_cours FROM cours ORDER BY titre_cours";
result = sta.executeQuery(requete);
while (result.next()) {
System.out.println(result.getString(1)+" --- "+ result.getString(2));
}
} catch(SQLException s){
s.getMessage();
}
finally {
result.close() ;
sta.close() ;
con.close() ;
}
}
}
cool-abdoul
Messages postés
96
Date d'inscription
dimanche 14 juin 2009
Statut
Membre
Dernière intervention
30 novembre 2010
9
27 oct. 2009 à 15:23
27 oct. 2009 à 15:23
çà marche !!!! voici la solution !!!!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author acoul
*/
public class NewClass {
public static void main (String [] args) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException{
Connection con = null ;
Statement sta = null ;
ResultSet result = null;
try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/tabase";
con = (Connection) DriverManager.getConnection(url,"user","motdepasse");
sta = (Statement) con.createStatement();
String requete = "SELECT description,titre_cours FROM cours ORDER BY titre_cours";
result = sta.executeQuery(requete);
while (result.next()) {
System.out.println(result.getString(1)+" --- "+ result.getString(2));
}
result.close() ;
sta.close() ;
con.close() ;
} catch(SQLException s){
s.getMessage();
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author acoul
*/
public class NewClass {
public static void main (String [] args) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException{
Connection con = null ;
Statement sta = null ;
ResultSet result = null;
try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/tabase";
con = (Connection) DriverManager.getConnection(url,"user","motdepasse");
sta = (Statement) con.createStatement();
String requete = "SELECT description,titre_cours FROM cours ORDER BY titre_cours";
result = sta.executeQuery(requete);
while (result.next()) {
System.out.println(result.getString(1)+" --- "+ result.getString(2));
}
result.close() ;
sta.close() ;
con.close() ;
} catch(SQLException s){
s.getMessage();
}
}
}