Paket dao;
Java.sql.*importieren;
öffentliche Klasse -Basisao {
//Orakel
// private statische endgültige String -Dirver = "oracle.jdbc.driver.oracledriver";
// Private statische endgültige String -String -URL = "JDBC: Oracle: Thin: @LocalHost: 1521: xe";
// private statische String -Zeichenfolge name = "admin";
// Private statische endgültige String -Pass = "123";
// sqlserver
// private statische endgültige String -Dirver = "com.microsoft.sqlserver.jdbc.sqlserverdriver";
// private statische endgültige Zeichenfolge url = "jdbc:
// private statische endgültige Zeichenfolge name = "sa";
// Private statische endgültige String -Pass = "SA";
// Mysql
private statische endgültige String -Dirver = "com.mysql.jdbc.driver";
private statische endgültige Zeichenfolge url = "JDBC: MySQL: //127.0.0.1: 3306/Schule";
private statische endgültige Zeichenfolge name = "root";
private statische endgültige String -Pass = "123456";
öffentliche Verbindung getCconnection ()
{
Verbindung conn = null;
versuchen {
Class.Forname (Dirver);
conn = driverManager.getConnection (URL, Name, Pass);
} catch (Ausnahme e) {
E. printstacktrace ();
}
Conn zurückgeben;
}
öffentlicher Leerraum Closall (Verbindungsconn, PrepectStatement PS, Ergebnis Rs)
{
versuchen {
if (null! = rs)
rs.close ();
if (null! = ps)
ps.close ();
if (null! = conn)
conn.close ();
} catch (Ausnahme e) {
E. printstacktrace ();
}
}
public int executeUpdate (String SQL, String Parms [])
{
Verbindung conn = null;
PrepedStatement ps = null;
int result = -1;
versuchen {
conn = getCconnection ();
ps = conn.preparestatement (SQL);
if (null! = parms) {
für (int i = 0; i <parms.length; i ++) {
ps.setstring (i+1, parm [i]);
}
}
result = ps.executeUpdate ();
ausführen();
} catch (Ausnahme e) {
System.out.println (e.getMessage ());
}Endlich{
Closall (Conn, Ps, Null);
}
Rückgabeergebnis;
}
öffentliche statische Leere Main (String [] Args) löst Ausnahme aus
{
Basierendao b = new -basiertao ();
Connection con = B.GetCConnection ();
System.out.println (con.isclosed ());
}
}