listing 11-1.java

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

JAVA
55
字号
import java.sql.*;
public class ModelA 
{
  private Connection Database;
  private Statement DataRequest;
  public ModelA ()
  {
    String url = "jdbc:odbc:CustomerInformation";
    String userID = "jim";
    String password = "keogh";
    try {
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
      Database = 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);
      if(Database != null) {
        try {
          Database.close();
        }
        catch(SQLException er){}
        }
      System.exit(2);	
   }
   try {
     // insert example code here
   }
   catch ( SQLException error ) {
     System.err.println("SQL error." + error);
     if(Database != null) {
       try {
         Database.close();
       }
       catch(SQLException er){}
       }
     System.exit(3);
     }
     if(Database != null) {
       try {
         Database.close();
       }
       catch(SQLException er){}
       }
     }
  public static void main ( String args [] )
  {
    final ModelA sql1 = new ModelA ();
    System.exit ( 0 ) ;
  }
}

⌨️ 快捷键说明

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