我弄的jsp程序出现以下错误,我是按书上打得代码。sql2000的sp4补丁已经装上。jdbc也配置好端口1433已开
Anerroroccurredatline:43inthejspfile:/basic/link.jspstmtcannotberesolved40:Stmt=conn....
An error occurred at line: 43 in the jsp file: /basic/link.jsp
stmt cannot be resolved
40: Stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
41: ResultSet.CONCUR_UPDATABLE);
42: String sql="select top 10*from authors";
43: ResultSet rs=stmt.executeQuery(sql);
44: while(rs.next()){%>
45: <tr>
46: <td><%=rs.getString("au_id")%></td>
An error occurred at line: 59 in the jsp file: /basic/link.jsp
stmt cannot be resolved
56: <%}%>
57: <%out.print("恭喜你,数据库访问成功!");%>
58: <%rs.close();
59: stmt.close();
60: conn.close();
61: %>
62: </table>
代码如下:
<%@page contentType="text/html;charest=gb2312" language="java" import="java.sql.*"errorPage=""%>
<!DOCTYPE HTML PUBLIC"_//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>
使用jdbc连接数据库
</title>
<style type="text/css">
<!--
.style{color:#FFOOOO;
font-size:24px;
}
-->
</style>
</head>
<body>
<div align="center"><span class="style1">JDBC直接访问数据库</span><BR>
</div>
<hr>
<BR>
<table border=2 bordercolor="#FF0000" align="center">
<tr>
<td>au_id</td>
<td>au_lname</td>
<td>au_fname</td>
<td>phone</td>
<td>address</td>
<td>city</td>
<td> state</td>
<td> zip</td>
<td> contract</td>
</tr>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDrive").newInstance();
String url="jdbc:microsoft:sqlserver;//localhost:1433;DatabaseName= plus";
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement
Stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql="select top 10*from authors";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){%>
<tr>
<td><%=rs.getString("au_id")%></td>
<td><%=rs.getString("au_lname")%></td>
<td><%=rs.getString("au_fname")%></td>
<td><%=rs.getString("phone")%></td>
<td><%=rs.getString(" address")%></td>
<td><%=rs.getString(" city")%></td>
<td><%=rs.getString(" state")%></td>
<td><%=rs.getString("zip")%></td>
<td><%=rs.getString("contract")%></td>
</tr>
<%}%>
<%out.print("恭喜你,数据库访问成功!");%>
<%rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
不知道是代码的问题还是我没配置好!跪求高手解决! 展开
stmt cannot be resolved
40: Stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
41: ResultSet.CONCUR_UPDATABLE);
42: String sql="select top 10*from authors";
43: ResultSet rs=stmt.executeQuery(sql);
44: while(rs.next()){%>
45: <tr>
46: <td><%=rs.getString("au_id")%></td>
An error occurred at line: 59 in the jsp file: /basic/link.jsp
stmt cannot be resolved
56: <%}%>
57: <%out.print("恭喜你,数据库访问成功!");%>
58: <%rs.close();
59: stmt.close();
60: conn.close();
61: %>
62: </table>
代码如下:
<%@page contentType="text/html;charest=gb2312" language="java" import="java.sql.*"errorPage=""%>
<!DOCTYPE HTML PUBLIC"_//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>
使用jdbc连接数据库
</title>
<style type="text/css">
<!--
.style{color:#FFOOOO;
font-size:24px;
}
-->
</style>
</head>
<body>
<div align="center"><span class="style1">JDBC直接访问数据库</span><BR>
</div>
<hr>
<BR>
<table border=2 bordercolor="#FF0000" align="center">
<tr>
<td>au_id</td>
<td>au_lname</td>
<td>au_fname</td>
<td>phone</td>
<td>address</td>
<td>city</td>
<td> state</td>
<td> zip</td>
<td> contract</td>
</tr>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDrive").newInstance();
String url="jdbc:microsoft:sqlserver;//localhost:1433;DatabaseName= plus";
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement
Stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql="select top 10*from authors";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){%>
<tr>
<td><%=rs.getString("au_id")%></td>
<td><%=rs.getString("au_lname")%></td>
<td><%=rs.getString("au_fname")%></td>
<td><%=rs.getString("phone")%></td>
<td><%=rs.getString(" address")%></td>
<td><%=rs.getString(" city")%></td>
<td><%=rs.getString(" state")%></td>
<td><%=rs.getString("zip")%></td>
<td><%=rs.getString("contract")%></td>
</tr>
<%}%>
<%out.print("恭喜你,数据库访问成功!");%>
<%rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
不知道是代码的问题还是我没配置好!跪求高手解决! 展开
3个回答
展开全部
Statement Stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
这里这个Stmt是大写的,而关闭这里stmt.close(); stmt是小写的,当然找不到符号了。注意大小写要一致。
这里这个Stmt是大写的,而关闭这里stmt.close(); stmt是小写的,当然找不到符号了。注意大小写要一致。
追问
上边的问题好了可是又有:org.apache.jasper.JasperException: An exception occurred processing JSP page /basic/link.jsp at line 38
35: String url="jdbc:microsoft:sqlserver;//localhost:1433;DatabaseName= plus";
36: String user="sa";
37: String password="";
38: Connection conn= DriverManager.getConnection(url,user,password);
39: Statement
追答
sa用户应该是有密码的,而这里的密码为空,估计是无法访问到数据库,你看看你的sa用户的密码是多少。
给你一个例子,差不多的,你看看:
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +"databaseName=ystour;user=cb;password=chenbing123;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(connectionUrl);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String sql="select * from hotel where HotelID="+request.getParameter("id")+"";
ResultSet rs=stmt.executeQuery(sql);
展开全部
同意一楼~大小写不一致~
追问
我又仔细看了下代码上边的问题好了可是又有:org.apache.jasper.JasperException: An exception occurred processing JSP page /basic/link.jsp at line 38
35: String url="jdbc:microsoft:sqlserver;//localhost:1433;DatabaseName= plus";
36: String user="sa";
37: String password="";
38: Connection conn= DriverManager.getConnection(url,user,password);
39: Statement。。还有SQLserverdriver我打错了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC"_//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>使用jdbc连接数据库</title>
<style type="text/css">
<!--
.style {
color: #FFOOOO;
font-size: 24px;
}
-->
</style>
</head>
<body>
<div align="center">
<span class="style1">JDBC直接访问数据库</span>
<BR>
</div>
<hr>
<BR>
<table border="2" bordercolor="#FF0000" align="center">
<tr>
<td>
au_id
</td>
<td>
au_lname
</td>
<td>
au_fname
</td>
<td>
phone
</td>
<td>
address
</td>
<td>
city
</td>
<td>
state
</td>
<td>
zip
</td>
<td>
contract
</td>
</tr>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDrive")
.newInstance();
String url = "jdbc:microsoft:sqlserver;//localhost:1433;DatabaseName= plus";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select top 10*from authors";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
%>
<tr>
<td><%=rs.getString("au_id")%></td>
<td><%=rs.getString("au_lname")%></td>
<td><%=rs.getString("au_fname")%></td>
<td><%=rs.getString("phone")%></td>
<td><%=rs.getString(" address")%></td>
<td><%=rs.getString(" city")%></td>
<td><%=rs.getString(" state")%></td>
<td><%=rs.getString("zip")%></td>
<td><%=rs.getString("contract")%></td>
</tr>
<%
}
%>
<%
out.print("恭喜你,数据库访问成功!");
%>
<%
rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
<!DOCTYPE HTML PUBLIC"_//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>使用jdbc连接数据库</title>
<style type="text/css">
<!--
.style {
color: #FFOOOO;
font-size: 24px;
}
-->
</style>
</head>
<body>
<div align="center">
<span class="style1">JDBC直接访问数据库</span>
<BR>
</div>
<hr>
<BR>
<table border="2" bordercolor="#FF0000" align="center">
<tr>
<td>
au_id
</td>
<td>
au_lname
</td>
<td>
au_fname
</td>
<td>
phone
</td>
<td>
address
</td>
<td>
city
</td>
<td>
state
</td>
<td>
zip
</td>
<td>
contract
</td>
</tr>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDrive")
.newInstance();
String url = "jdbc:microsoft:sqlserver;//localhost:1433;DatabaseName= plus";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select top 10*from authors";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
%>
<tr>
<td><%=rs.getString("au_id")%></td>
<td><%=rs.getString("au_lname")%></td>
<td><%=rs.getString("au_fname")%></td>
<td><%=rs.getString("phone")%></td>
<td><%=rs.getString(" address")%></td>
<td><%=rs.getString(" city")%></td>
<td><%=rs.getString(" state")%></td>
<td><%=rs.getString("zip")%></td>
<td><%=rs.getString("contract")%></td>
</tr>
<%
}
%>
<%
out.print("恭喜你,数据库访问成功!");
%>
<%
rs.close();
stmt.close();
conn.close();
%>
</table>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询