在NetBeans里的jsp用了preparedstatement后连接MySQL显示的表格里为什么不出数据?代码如下
<%@pageimport="java.sql.SQLException"%><%@pagecontentType="text/html"%><%@pagepageEnc...
<%@page import="java.sql.SQLException"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
java.sql.Connection conn=null;
java.lang.String strConn;
java.sql.PreparedStatement preparedStmt=null;//语句对象
java.sql.ResultSet sqlRst=null;//结果集对象
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/piao","root","12345");
//=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
preparedStmt=conn.prepareStatement("select trainid,startnet,endnet from train where startnet=?");
//设置参数
String parm=request.getParameter("parm");
preparedStmt.setString(1,"%"+parm+"%");
//执行SQL语句
sqlRst=preparedStmt.executeQuery();
%>
<center>火车信息</center>
<table border="1" width="100%" bordercolorlight="#CC99FF" cellpadding="2" bordercolordark="#FFFFFF" cellspacing="0"
<tr>
<td align="center">车次</td>
<td align="center">始发站</td>
<td align="center">终点站</td>
</tr>
<% while(sqlRst.next()){//取得下一条记录
%>
<tr><!--显示记录-->
<td><%=sqlRst.getString("trainid")%></td>
<td><%=new String(sqlRst.getString("startnet"))%></td>
<td><%="endnet" %></td>
</tr>
<%}%>
</table>
<%
}catch(java.sql.SQLException e){
out.println(e.toString());
}finally{
//关闭结果集对象
if(sqlRst!=null)try{sqlRst.close();} catch(java.sql.SQLException e1){
out.println(e1.toString());
}finally{
try{
//关闭语句对象
if(preparedStmt!=null)preparedStmt.close();
}catch(java.sql.SQLException e2){
out.println(e2.toString());
}finally{
try{
//关闭数据库连接
if(conn!=null)conn.close();
}catch(java.sql.SQLException e3){
out.println(e3.toString());
}
}
}
}
%> 展开
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
java.sql.Connection conn=null;
java.lang.String strConn;
java.sql.PreparedStatement preparedStmt=null;//语句对象
java.sql.ResultSet sqlRst=null;//结果集对象
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/piao","root","12345");
//=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
preparedStmt=conn.prepareStatement("select trainid,startnet,endnet from train where startnet=?");
//设置参数
String parm=request.getParameter("parm");
preparedStmt.setString(1,"%"+parm+"%");
//执行SQL语句
sqlRst=preparedStmt.executeQuery();
%>
<center>火车信息</center>
<table border="1" width="100%" bordercolorlight="#CC99FF" cellpadding="2" bordercolordark="#FFFFFF" cellspacing="0"
<tr>
<td align="center">车次</td>
<td align="center">始发站</td>
<td align="center">终点站</td>
</tr>
<% while(sqlRst.next()){//取得下一条记录
%>
<tr><!--显示记录-->
<td><%=sqlRst.getString("trainid")%></td>
<td><%=new String(sqlRst.getString("startnet"))%></td>
<td><%="endnet" %></td>
</tr>
<%}%>
</table>
<%
}catch(java.sql.SQLException e){
out.println(e.toString());
}finally{
//关闭结果集对象
if(sqlRst!=null)try{sqlRst.close();} catch(java.sql.SQLException e1){
out.println(e1.toString());
}finally{
try{
//关闭语句对象
if(preparedStmt!=null)preparedStmt.close();
}catch(java.sql.SQLException e2){
out.println(e2.toString());
}finally{
try{
//关闭数据库连接
if(conn!=null)conn.close();
}catch(java.sql.SQLException e3){
out.println(e3.toString());
}
}
}
}
%> 展开
2个回答
TableDI
2024-07-18 广告
2024-07-18 广告
`VLOOKUP` 匹配出错误的数据通常是由于以下几个原因:1. **查找值错误**:输入的查找值与数据源中的值不匹配,可能是因为拼写错误、大小写不一致或存在不可见的字符。2. **查找区域设置错误**:查找区域的首列必须包含要查找的值,且...
点击进入详情页
本回答由TableDI提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询