设为首页 加入收藏

TOP

Java 获得Oracle 的错误代码
2014-11-24 02:09:05 来源: 作者: 【 】 浏览:0
Tags:Java 获得 Oracle 错误 代码

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;


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安全管理器 下一篇3种Linux Shell自动交互的方法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: