package dao;
Importer java.sql. *;
classe publique basé sur le plan basé {
//oracle
// chaîne finale statique privée dirver = "oracle.jdbc.driver.oracledriver";
// Url de chaîne finale statique privée = "jdbc: oracle: mince: @localhost: 1521: xe";
// la chaîne finale statique privée name = "admin";
// String statique final privé Pass Pass = "123";
// SQLServer
// chaîne finale statique privée dirver = "com.microsoft.sqlserver.jdbc.sqlServerDriver";
// Url de chaîne finale statique privée = "jdbc: sqlServer: // localhost: 1433; databasename = tbldb";
// la chaîne finale statique privée name = "SA";
// chaîne finale statique privée Pass = "SA";
// mysql
chaîne finale statique privée dirver = "com.mysql.jdbc.driver";
Url de chaîne finale statique privée = "JDBC: mysql: //127.0.0.1: 3306 / école";
Nom de chaîne finale statique privée = "root";
String final statique privé Pass = "123456";
Connexion publique getCConnection ()
{
Connexion conn = null;
essayer {
Class.forname (dirver);
Conn = driverManager.getConnection (URL, nom, pass);
} catch (exception e) {
e.printStackTrace ();
}
Retourne Conn;
}
Closal de vide public (Connexion Conn, préparation PS, ResultSet RS)
{
essayer {
if (null! = RS)
Rs.Close ();
if (null! = ps)
ps.close ();
if (null! = Conn)
conn.close ();
} catch (exception e) {
e.printStackTrace ();
}
}
public int ExecuteUpDate (String SQL, String Parms [])
{
Connexion conn = null;
PréparedStatement PS = null;
INT Result = -1;
essayer {
Conn = getCConnection ();
ps = conn.preparestatement (SQL);
if (null! = parms) {
pour (int i = 0; i <parms.length; i ++) {
ps.SetString (i + 1, parms [i]);
}
}
result = ps.ExecuteUpdate ();
exécuter();
} catch (exception e) {
System.out.println (e.getMessage ());
}enfin{
Closall (Conn, PS, null);
}
Résultat de retour;
}
public static void Main (String [] args) lève une exception
{
Basedao b = new-basesao ();
Connexion con = b.getcconnection ();
System.out.println (con.isclosed ());
}
}