listing 10-11.java

来自「这是JAVA开发大全的源代码」· Java 代码 · 共 32 行

JAVA
32
字号
String url = "jdbc:odbc:CustomerInformation";
String userID = "jim";
String password = "keogh";
ResultSet Results;
Connection Db;
try {
   Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
   Db = DriverManager.getConnection(url,userID,password);
 }
catch (ClassNotFoundException error) {
      System.err.println(
             "Unable to load the JDBC/ODBC bridge." + error);
      System.exit(1);
}
catch (SQLException error) {
      System.err.println("Cannot connect to the database." + error);
      System.exit(2);
}
try {
      String query = "SELECT * FROM Customers WHERE CustNumber = ?";
      PreparedStatement pstatement = Db.preparedStatement(query);
      pstatement.setString(1, "123");
      Results = pstatement.executeQuery ();
      //Place code here to interact with the ResultSet
      pstatement.close();
 }
catch ( SQLException error ){
     System.err.println("SQL error." + error);
     System.exit(3);
}
Db.close();

⌨️ 快捷键说明

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