extractsqlexceptioninfo.java

来自「此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作」· Java 代码 · 共 37 行

JAVA
37
字号
import java.sql.*;public class ExtractSQLExceptionInfo {  public static void main(String[] args) {    String url = "jdbc:cloudscape:Wrox4370.db";    String driver = "COM.cloudscape.core.JDBCDriver";    String username = "guest";    String password = "guest";    String theStatement =       "SELECT recordingid, recordingtitle, coverimagefilespec FROM rekordings";    // intentional misspelling to generate exception    try {      Class.forName(driver);      Connection connection = DriverManager.getConnection(url, username,               password);      Statement queryRecordings = connection.createStatement();      ResultSet theResults = queryRecordings.executeQuery(theStatement);      queryRecordings.close();    } catch (ClassNotFoundException cnfe) {      System.err.println(cnfe);    } catch (SQLException sqle) {      String sqlMessage = sqle.getMessage();      String sqlState = sqle.getSQLState();      int vendorCode = sqle.getErrorCode();      System.err.println("Exception occurred:");      System.err.println("Message: " + sqlMessage);      System.err.println("SQL state: " + sqlState);      System.err.println("Vendor code: " + vendorCode                          + "\n----------------");    }   } }

⌨️ 快捷键说明

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