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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| // Launch est mon main`
public class Launch {
/**
* @param args
*/
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
Manager.getInstance().lancer();
}
}
// Dans ma classe ConnectionTB se trouve les méthodes pour la connexion
/**
* Loading JDBC drivers
*/
public void loadingDriver(){
try {
//loading JDBC drivers
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Loading JDBC drivers ok.");
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
}
/**
* ConnectionTB Method
* @return a bDD of type Connection
*/
public Connection toConnect(){
try{
this.bDD = DriverManager.getConnection(this.getUrl(), this.getUser(), this.getPasswd());
if(!this.bDD.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
this.bDD.setAutoCommit(false);
}
catch(SQLException e){
System.out.println("erreur connection DataBase."+e);
}
return this.bDD;
}
// Et voilou la Manager où j'ai un problème pour créer un statement.
public class Manager {
/**
* Attributes
*/
private static Manager moi;
private Connection bDD;
/**
* Default constructor
*/
public Manager(){
this.bDD = null;
}
/**
* @return the reference to the single instance of the Manager
*/
public static Manager getInstance(){
if(moi==null) moi = new Manager();
return moi;
}
public void lancer(){
String name = "nameBase";
String url = "jdbc:mysql://localhost:8889/";
String user = "root";
String passwd = "root";
ConnectionTB cTB = null;
Statement s = null;
cTB = new ConnectionTB(name, url, user, passwd);
try {
cTB.loadingDriver();
cTB.toConnect();
} catch (Exception e) {
System.out.println("no connect.");
}
try {
s = bDD.reateStatement();
} catch (Exception e) {
}
try {
cTB.disconnect();
} catch (Exception e) {
System.out.println("no disconnect.");
}
} |
Partager