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
|
package com.essai;
import java.sql.*;
public class Personne {
Connection con=null;
PreparedStatement pst=null;
Statement st=null;
ResultSet rs=null;
String url="jdbc:mysql://localhost:3306/essai";
String user="root";
String pwd="mysql";
public void connect(){
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection(url,user,pwd);
//st=con.createStatement();
}catch(ClassNotFoundException c){
}catch(SQLException s){}
}
public void inscrire( String nom,String prenom,String age,String adresse){
connect();
try{
pst=con.prepareStatement("insert into personne values(?,?,?,?)");
pst.setString(1,nom);
pst.setString(2,prenom);
pst.setString(3,age);
pst.setString(4,adresse);
pst.executeUpdate();
}catch(SQLException s){}
}
}; |
Partager