?? listing 10-18.java
字號:
String url = "jdbc:odbc:CustomerInformation";
String userID = "jim";
String password = "keogh";
Statement DataRequest;
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 FirstName,LastName FROM Customers";
DataRequest = Db.createStatement(CONCUR_UPDATABLE);
Results = DataRequest.executeQuery (query);
}
catch ( SQLException error ){
System.err.println("SQL error." + error);
System.exit(3);
}
boolean Records = Results.next();
if (!Records ) {
System.out.println("No data returned");
System.exit(4);
}
try {
Results.updateString (1, "Tom");
Results.updateString (2, "Smith");
Results.insertRow();
DataRequest.close();
}
catch (SQLException error ) {
System.err.println("Data display error." + error);
System.exit(5);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -