databasemanager.java

来自「java 完全探索的随书源码」· Java 代码 · 共 46 行

JAVA
46
字号
import java.sql.*;import java.util.*;import sun.jdbc.odbc.*;public class DatabaseManager{  // These properties could come from a system configuration file  static private String urlHeader = "jdbc:polite:";  static private String databaseName = "POLITE";  static private String user = "SYSTEM";  static private String password = "";  static private String driverName = "oracle.lite.poljdbc.POLJDBCDriver";  public static Connection getConnection()  {    // Define the local Connection instance that gets returned    Connection conn = null;    try    {      // Load the JDBC driver      Class.forName( driverName );      // Get an instance of the Connection. Really the Connection is an      // interface that some class implements.      // Concat the three parts together to build the full URL      String databaseURL = urlHeader + databaseName;      conn = DriverManager.getConnection( databaseURL, user, password );    }    catch( ClassNotFoundException ex )    {      // The JDBC driver class could not be found      ex.printStackTrace();      System.exit( -1 );    }    catch( SQLException ex )    {      // A sql exception occured, for now just print out the stack trace      ex.printStackTrace();    }    return conn;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?