1. SQL server 2000 database connection method:
Copy codeThe Code is as follows:
Connection con;
Public Connection getCon (){
Try {Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver"); // load the driver
Con = DriverManger. getConnection ("jdbc: microsoft: sqlServer: // localhost: 1433; DatabaseName = aa", "sa", ""); // try to establish a connection to a given Database URL
} Catch (ClassNotFoundException e ){
E. printStackTrace ();
} Catch (SQLException e ){
E. printStackTrace ();
}
Return con;
}
2. SQL server 2005 database connection method:
Copy codeThe Code is as follows:
Connection con;
Public Connection getCon (){
Try {
Class. forName ("com. microsoft. sqlserver. jdbc. SQLServerDriver"); // load the driver
Con = DriverManger. getConnection ("jdbc: microsoft: sqlServer: // localhost: 1433; DatabaseName = aa", "sa", ""); // try to establish a connection to a given Database URL
} Catch (ClassNotFoundException e ){
E. printStackTrace ();
} Catch (SQLException e ){
E. printStackTrace ();
}
Return con;
}
3. oracle Data Connection Method
Copy codeThe Code is as follows:
Connection con;
Public Connection getCon (){
Try {
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Con = DriverManger. getConnection ("jdbc: oracle: thin: @ 127.0.0.1: 1521: oracle", "scott", "tiger ");
} Catch (Exception e ){
E. printStackTrace ();
}
Return con;
}