背景:
阅读新闻
Java 获得Oracle 的错误代码
[日期:2009-12-06] 来源:Java社区 作者:Java [字体:]
import Java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SqlException {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
String driver = "Oracle.jdbc.driver.OracleDriver";
Class.forName(driver).newInstance();
System.out.println("Connecting to database...");
String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:ORCL";
conn = DriverManager.getConnection(jdbcUrl, "yourName", "mypwd");
stmt = conn.createStatement();
try {
rs = stmt.executeQuery("Select * from no_table_exisits");
} catch (SQLException seRs) {
String exMsg = "Message from MySQL Database";
String exSqlState = "Exception";
SQLException mySqlEx = new SQLException(exMsg, exSqlState);
seRs.setNextException(mySqlEx);
throw seRs;
}
} catch (SQLException se) {
int count = 1;
while (se != null) {
System.out.println("SQLException " + count);
System.out.println("Code: " + se.getErrorCode());
System.out.println("SqlState: " + se.getSQLState());
System.out.println("Error Message: " + se.getMessage());
se = se.getNextException();
count++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
相关资讯 Java
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯