[MySQL JEE] Statement marche pas?
Bonjour, je vous copie colle mon code qui consiste à me connecter à ma BDD MySQL pour ajouter de valeurs (ajout de membre).
Seulement le pb est qu'apparement ça bloque au niveau du statement mais je vois vraiment pas pourquoi...
Avez vous une idée pour réparer mon code? J'arrive plus à voir :s
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
| import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Ajout_membre
{
private Connection connection = null;
Statement s = null;
public void Connect()
{
try {
// Load the JDBC driver
String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "biblio";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "root";
String password = "monpass";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
}
public int add_member(String nom, String prenom)
{
try {
s = connection.createStatement ( );
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
s.executeQuery ("INSERT INTO membre (nom_eleve, prenom_eleve) VALUES ('"+nom+"', '"+prenom+"')");
System.out.println("baaaaaaaaaaaa");
} catch (SQLException e) {
e.printStackTrace();
}
return 0;
}
public static void main(String[] args)
{
Ajout_membre am = new Ajout_membre();
am.Connect();
am.add_member("test1","test2");
}
} |