📄 listing 11-1.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -