Here, we mainly use some commonly used databases, and paste these items here to facilitate future queries. The network can be used as a reference. ** Four Common Database Connection Methods * publicclassSQLMode {** oracle driver connection method: Port Number 1521 * privatestaticStringOracleDri
Here, we mainly use some commonly used databases, and paste these items here to facilitate future queries. The network can be used as a reference. /** Four Common Database Connection Methods */public class SQLMode {/** oracle driver connection method: Port Number 1521 */private static String OracleDri
Here, we mainly use some commonly used databases, and paste these items here to facilitate future queries. The network can be used as a reference.
/** Four Common Database Connection Methods */
Public class SQLMode {
/** Oracle driver connection method: Port Number 1521 */
Private static String OracleDriver = "Oracle. jdbc. Driver. OracleDriver ";
Private static String url = "jdbc: Oracle: thin: @ localhost: 1521: mydata ";
/** MySQL driver connection method: Port Number 3306 */
Private static String MysqlDriver = "com. mysql. jdbc. Driver ";
Private static String url2 = "jdbc: mysql:/localhost: 3306/mydata ";
/** SQL server2005 DRIVER: Port Number 1433 */
Private static String sqlDriver = "com. microsoft. jdbc. sqlserver. SQLServerDriver"; // Method for connecting to the SQL database
Private static String url3 = "jdbc: microsoft: sqlserver: // localhost: 1433;" +
"DatabaseName = mydata ";
/* JDBC-ODBC access database */
Private static String accessDriver = "sun. jdbc. odbc. JdbcOdbcDriver ";
Private static String url4 = "jdbc: odbc: mydata"; // The system prompts you to configure access to load the data source.
// Open control panel --> performance and maintenance --> management tools --> data source (ODBC) --> Add
Private static String user = "admin ";
Private static String pwd = "password ";
/** Get Access connection */
Public static Connection getAccessCon (){
Try {
Class. forName (accessDriver );
Connection oracle = DriverManager. getConnection (url4, user, pwd );
Return oracle;
} Catch (Exception e ){
E. printStackTrace ();
Throw new RuntimeException (e );
}
}
/** Obtain the SQL Server connection */
Public static Connection getsqlSerCon (){
Try {
Class. forName (sqlDriver );
Connection sqlSer = DriverManager. getConnection (url3, user, pwd );
Return sqlSer;
} Catch (Exception e ){
E. printStackTrace ();
Throw new RuntimeException (e );
}
}
/** Obtain the Oracle connection */
Public static Connection getOracleCon (){
Try {
Class. forName (OracleDriver );
Connection oracle = DriverManager. getConnection (url, user, pwd );
Return oracle;
} Catch (Exception e ){
E. printStackTrace ();
Throw new RuntimeException (e );
}
}
/** Obtain mysql connection */
Public static Connection mysqlCon (){
Try {
Class. forName (MysqlDriver );
Connection mysql = DriverManager. getConnection (url2, user, pwd );
Return mysql;
} Catch (Exception e ){
Throw new RuntimeException (e );
}
}