首页新闻找找看学习计划

初学java web。jsp页面上连接oracle数据库报错,求大神指教。

0
悬赏园豆:10 [已解决问题] 解决于 2013-08-18 16:03

<%@ page contentType = "text/html" pageEncoding = "utf-8"%>
<%@ page import = "java.sql.*"%>
<html>
<head><title>www.lk.com</title></head>
<body>
<%!
public static final String DBDRIVER = "oracle.jdbc.Driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1502:hte";
public static final String DBUSER = "system";
public static final String DBPASS = "lukai138628";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
%>
<%
try{
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String sql = "select empon, ename, job, hiredate, sal from emp";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
%>

<center>
<table border = "1" width = "80%">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>

</tr>
<%
while(rs.next())
{
int empon = rs.getInt(1);
String ename = rs.getString(2);
String job = rs.getString(3);
String date = rs.getString(4);
Float sal = rs.getFloat(5);


%>
<tr>
<td><%=empon%></td>
<td><%=ename%></td>
<td><%=job%></td>
<td><%=sal%></td>
<td><%=date%><td>
</tr>
<%
}
%>
</table>
</center>
<%
}catch(Exception e){
System.out.println(e);
}finally{
rs.close();
pstmt.close();
conn.close();
}
%>
</body>
</html>

 

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /list.jsp at line 64

61: }catch(Exception e){
62: 		System.out.println(e);
63: }finally{
64: 		rs.close();
65: 		pstmt.close();
66: 		conn.close();
67: }


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

root cause

java.lang.NullPointerException
	org.apache.jsp.list_jsp._jspService(list_jsp.java:134)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.

heilao的主页 heilao | 初学一级 | 园豆:70
提问于:2013-08-14 22:03
< >
分享
最佳答案
0

public static final String DBDRIVER = "oracle.jdbc.Driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1502:hte";

 

Driver 改成 driver

端口号改成1521

把oracle的驱动放在\Tomcat 6.0\lib就可以了。

heilao | 初学一级 |园豆:70 | 2013-08-18 16:02
其他回答(2)
0

你这个代码写得,后台代码肿么全整到jsp页面?不利于复用。

      rs.close();
 		pstmt.close();
 		conn.close();


关闭的时候判断一下是否为null

不行网上搜索java jdbc
收获园豆:5
Beyond-bit | 园豆:2663 (老鸟四级) | 2013-08-14 22:30
0

同上。有个异常是空指针异常,说明有个值为null,无法close。

看你sql语句那hiredate应该是个Date类型的字段,可以用rs.getString来接收?

收获园豆:5
Mr.Er | 园豆:215 (菜鸟二级) | 2013-08-14 23:36

我设定的是String类型的。

支持(0) 反对(0) heilao | 园豆:70 (初学一级) | 2013-08-18 13:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册