JavaBean代码
package database;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002 Yaoguodong</p>
* <p>Company: </p>
* @author unascribed YaoGuodong
* @email net_spirit@163.com
* @version 1.0
*/
public class DBconnect {
private String strDBDriver="oracle.jdbc.driver.OracleDriver";
private String strConnstr="jdbc
racle:thin
192.168.0.68:1521:dynasty";
Connection conn=null;
ResultSet rs=null;
Statement stmt=null;
//构造函数
public DBconnect(){
try{
Class.forName(strDBDriver);
conn = DriverManager.getConnection(strConnstr,"dynasty","dynasty");
stmt=conn.createStatement();
}
catch(Exception e){
System.out.println(e);
}
}
public ResultSet executeQuery(String sql){
try{
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.out.println("执行SQL语句出错: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql) {
try {
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("执行SQL语句出错: " + ex.getMessage());
}
}
public Connection getConnection(){
return conn;
}
public boolean close(){
try{
if(this.rs!=null){ this.rs.close();
}
if(stmt!=null){ this.stmt.close();
}
if(conn!=null){ this.conn.close();
}
return true;
}catch(Exception err){
return false;
}
}
}
JSP文件
<html>
<head>
<title>Connect Database test!</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<%@page contentType="text/html;charset=gb2312"%>
<%@page language="java" import="java.sql.*" %>
<%@page import="oracle.jdbc.driver.*" %>
<%@page import="database.*" %>
<jsp:useBean id="connect" scope="page" class="database.DBconnect" />
</head>
<body>
<table border=1 align="center">
545454645645645
<%
//String sql="SELECT yong_hm,yong_hkl FROM yong_h";
%>
545454645645645
<%
//String sql="select * from yong_h";
ResultSet rs = connect.executeQuery("select * from yong_h");
//读queyrSql方法,返回结果集。
out.println("<tr><td align=center><font color=red>用户名</font></td>");
out.println("<td align=center><font color=red>密码</font></td></tr>");
while (rs.next())
{
String aa=rs.getString(1);
String bb=rs.getString(2);
%>
<tr><td><%=aa%></td><td><%=bb%></td></tr>
<%
}
out.println("<tr><td colspan=2> </td></tr>");
rs.close();
%>
</table>
</body>
</html>
报错信息:
执行SQL语句出错: ORA-00600: 内部错误代码,参数: [ttcgcshnd-1], [0], [], [], [],
[], [], []
java.lang.NullPointerException
at _login._datatest__jsp._jspService(/login/datatest.jsp:23)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:181)
at com.caucho.server.http.Invocation.service(Invocation.java:291)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:132)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:217)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:159)
at com.caucho.server.TcpConnection.run(TcpConnection.java:136)
at java.lang.Thread.run(Thread.java:484)