关于jsp找不到符号的问题

shadowjl 2008-08-06 10:09:27

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>修改数据时下拉列表的默认值为数据库中原数据信息</title>
<jsp:useBean id="connection" scope="request" class="com.JDBConnection"/>
<link href="Css/Css.css" type="text/css" rel="stylesheet">
</head>

<body>
<table width="500" height="259" border="0" align="center" cellpadding="0" cellspacing="0" background="images/0.jpg">
<tr align="center">
<td height="82" colspan="2"><strong><font color="#FFFFFF" size="+2">修改用户信息模块</font></strong></td>
</tr>
<tr>
<td width="87"> </td>
<td width="413" valign="top"><table width="382" border="0" align="center">
<tr align="center">
<td width="66">账号</td>
<td width="66">性别</td>
<td width="66">年龄</td>
<td width="66">职业</td>
<td width="84">操作</td>
</tr>
<%
String sql = "select * from tb_userInfo";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
String id = rs.getString(1);
%>
<tr align="center">
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><a href="dealwith.jsp?id=<%=id%>">修改</a></td>
</tr>
<%}
} catch (Exception e) {
}%>
</table></td>
</tr>
</table>
</body>



package com;
import java.sql.*;

public class JDBConnection {
private final String dbDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接sql数据库的方法
private final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_database03";
private final String userName = "sa";
private final String password = "";
private Connection con = null;

public JDBConnection() {
try {
Class.forName(dbDriver).newInstance(); //加载数据库驱动
} catch (Exception ex) {
System.out.println("数据库加载失败");
}
}

//创建数据库连接
public boolean creatConnection() {
try {
con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(true);

} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("creatConnectionError!");
}
return true;
}

//对数据库的增加、修改和删除的操作
public boolean executeUpdate(String sql) {

if (con == null) {
creatConnection();
}
try {
Statement stmt = con.createStatement();
int iCount = stmt.executeUpdate(sql);
System.out.println("操作成功,所影响的记录数为" + String.valueOf(iCount));
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("executeUpdaterError!");
}
return true;
}

//对数据库的查询操作
public ResultSet executeQuery(String sql) {
ResultSet rs;
try {
if (con == null) {
creatConnection();
}
Statement stmt = con.createStatement();
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("executeQueryError!");
return null;
}
return rs;
}

//关闭数据库的操作
public void closeConnection() {
if (con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
System.out.println("Failed to close connection!");
} finally {
con = null;
}
}
}

}

总提示ResultSet rs = connection.executeQuery(sql);中executeQuery找不到符号
...全文
306 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
energyom 2008-08-06
  • 打赏
  • 举报
回复
大家来看看这个难题啦,帮帮楼主这个问题少年吧
shadowjl 2008-08-06
  • 打赏
  • 举报
回复
表名没有问题
dsn21 2008-08-06
  • 打赏
  • 举报
回复
String sql = "select * from tb_userInfo"; 如果只是报找不到符号说明左侧的sql语句可能有问题 你看一下这个表的名称写对了吗?

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧