经过站内人士热心帮助,我得程序一次又一次的改进,不过还是有问题
我的jsp网页如下:zygjQuery.jsp:<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="GB2312"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>取得数据</title>
</head>
<body>
<CENTER><FONT size=5 color=blue>查询数据库,取得数据
</FONT></CENTER>
<BR><HR><BR>
<CENTER>
<%
//连接数据库
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.8:1521:orcl", "scott", "tiger");
Statement stmt =con.createStatement();
ResultSet rs = stmt.executeQuery("select * from scott.DANZHI where scott.DANZHI.id=3 ");
%>
<p>目前单质数据表如下:</p>
<table bgcolor=DodgerBlue>
<tr bgcolor=SkyBlue>
<td width="14%" height="16" align="center">炸药名称</td>
<td width="10%" align="center">外观</td>
<td width="9%" align="center">爆热</td>
<td width="8%" align="center">装药密度</td>
<td width="7%" align="center">爆速<br></td>
<td width="10%" align="center">爆压<br></td>
<td width="9%" align="center">粘度</td>
<td width="10%" align="center">摩擦感度</td>
<td width="10%" align="center">撞击感度</td>
<td width="11%" align="center">详细参数</td>
</tr>
<%
while (rs.next()){
%>
<tr>
<td bgcolor=LightYellow width="14%" height="16"><%=rs.getString("EXPLOSIVES_NAME") %></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("APPEARANCE")%></td>
<td bgcolor=LightYellow width="9%"><%=rs.getString("HOT_BLAST")%></td>
<td bgcolor=LightYellow width="8%"><%=rs.getString("CHARGE_DENSITY")%></td>
<td bgcolor=LightYellow width="7%"><%=rs.getString("DETONATION_VELOCITY")%></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("DETONATION_PRESSURE")%></td>
<td bgcolor=LightYellow width="9%"><%=rs.getString("VISCOSITY")%></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("FRICTION_SENSITIVITY")%></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("IMPACT_SENSITIVITY")%></td>
<td bgcolor=LightYellow width="11%"><a href="zyDetail.jsp"><center>查看</center></a></td>
</tr>
<%}}
catch (ClassNotFoundException e) {e.printStackTrace();}
catch (SQLException e) {e.printStackTrace();}
catch(NullPointerException e) {e.printStackTrace();}
%>
</table>
</CENTER>
</body>
</html>经过tomcat发布,没有异常出现。但是网页显示如下: 查询数据库,取得数据
--------------------------------------------------------------------------------就仅仅以上内容,下面连表格都不显示了。感觉我的程序从try(寻找异常)以后的内容在网页上显示不出来呀。
这到底是怎么回事?请教站内高手!
我的jsp网页如下:zygjQuery.jsp:<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="GB2312"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>取得数据</title>
</head>
<body>
<CENTER><FONT size=5 color=blue>查询数据库,取得数据
</FONT></CENTER>
<BR><HR><BR>
<CENTER>
<%
//连接数据库
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.8:1521:orcl", "scott", "tiger");
Statement stmt =con.createStatement();
ResultSet rs = stmt.executeQuery("select * from scott.DANZHI where scott.DANZHI.id=3 ");
%>
<p>目前单质数据表如下:</p>
<table bgcolor=DodgerBlue>
<tr bgcolor=SkyBlue>
<td width="14%" height="16" align="center">炸药名称</td>
<td width="10%" align="center">外观</td>
<td width="9%" align="center">爆热</td>
<td width="8%" align="center">装药密度</td>
<td width="7%" align="center">爆速<br></td>
<td width="10%" align="center">爆压<br></td>
<td width="9%" align="center">粘度</td>
<td width="10%" align="center">摩擦感度</td>
<td width="10%" align="center">撞击感度</td>
<td width="11%" align="center">详细参数</td>
</tr>
<%
while (rs.next()){
%>
<tr>
<td bgcolor=LightYellow width="14%" height="16"><%=rs.getString("EXPLOSIVES_NAME") %></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("APPEARANCE")%></td>
<td bgcolor=LightYellow width="9%"><%=rs.getString("HOT_BLAST")%></td>
<td bgcolor=LightYellow width="8%"><%=rs.getString("CHARGE_DENSITY")%></td>
<td bgcolor=LightYellow width="7%"><%=rs.getString("DETONATION_VELOCITY")%></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("DETONATION_PRESSURE")%></td>
<td bgcolor=LightYellow width="9%"><%=rs.getString("VISCOSITY")%></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("FRICTION_SENSITIVITY")%></td>
<td bgcolor=LightYellow width="10%"><%=rs.getString("IMPACT_SENSITIVITY")%></td>
<td bgcolor=LightYellow width="11%"><a href="zyDetail.jsp"><center>查看</center></a></td>
</tr>
<%}}
catch (ClassNotFoundException e) {e.printStackTrace();}
catch (SQLException e) {e.printStackTrace();}
catch(NullPointerException e) {e.printStackTrace();}
%>
</table>
</CENTER>
</body>
</html>经过tomcat发布,没有异常出现。但是网页显示如下: 查询数据库,取得数据
--------------------------------------------------------------------------------就仅仅以上内容,下面连表格都不显示了。感觉我的程序从try(寻找异常)以后的内容在网页上显示不出来呀。
这到底是怎么回事?请教站内高手!
那就改成out.println(e);也可以在每句代码后加一句out.println(xxxx);作为调试,看看哪里出了问题
---------------------
目前单质数据表如下: 编号 姓名 工资
1 hc 9999
2 luyi 38
3 XX 438
4 xhy 5438
5 oy 99
6 test 1
我用自己的Oracle数据库试了下!
是可以的!
你要确保你用的scott账号可以查出数据吗?你要查询的表可以用这个账号查询结果吗?
你把sql语句放到里面去测试!能查出来再说!
在最后把它们都释放掉!
rs.close();
stmt.close();
con.close();代码如下!基本是你的代码改的,用的自己的表!
<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="GB2312"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>取得数据 </title>
</head>
<body>
<CENTER> <FONT size=5 color=blue>查询数据库,取得数据
</FONT> </CENTER>
<BR> <HR> <BR>
<CENTER>
<%
//连接数据库
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "haha", "haha");
stmt =con.createStatement();
rs = stmt.executeQuery("select * from employee"); %>
<p>目前单质数据表如下: </p>
<table bgcolor=DodgerBlue>
<tr bgcolor=SkyBlue>
<td width="14%" height="16" align="center">编号 </td>
<td width="10%" align="center">姓名 </td>
<td width="9%" align="center">工资 </td>
</tr>
<%
while (rs.next()){
%>
<tr>
<td bgcolor=LightYellow width="14%" height="16"> <%=rs.getInt("ID") %> </td>
<td bgcolor=LightYellow width="10%"> <%=rs.getString("NAME")%> </td>
<td bgcolor=LightYellow width="9%"> <%=rs.getString("SALARY")%> </td>
</tr>
<%}
}
catch (ClassNotFoundException e1) {e1.printStackTrace();}
catch (SQLException e2) {e2.printStackTrace();}
catch(NullPointerException e3) {e3.printStackTrace();}
finally{
rs.close();
stmt.close();
con.close();
}
%>
</table>
</CENTER>
</body>
</html>