关于JSP连接数据库的问题,下面这样写是错的,请高手看一下怎么弄
<%@pagecontentType="text/html;charset=gb2312"%><%@pageimport="java.sql.*"%><html><bod...
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
String url ="jdbc:mysql://localhost/myjava?user=root&password=19950506&useUnicode=true&characterEncoding=GB2312" ;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String query="select Name from suser order by id";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
String s=rs.getString("Name");
out.print(s+"<br>");
}
%>
</body>
</html>
我的数据库:root 19950506
一个数据库:myjava 表 suser Name为varchar
type Exception report
message An exception occurred processing JSP page /working/L1judge.jsp at line 11
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 /working/L1judge.jsp at line 11
8: Connection conn= DriverManager.getConnection(url);
9: Statement stmt=conn.createStatement();
10: String query="select Name from suser order by id";
11: ResultSet rs=stmt.executeQuery(query);
12: while(rs.next())
13: {
14: String s=rs.getString("Name"); 展开
<%@ page import="java.sql.*"%>
<html>
<body>
<%
String url ="jdbc:mysql://localhost/myjava?user=root&password=19950506&useUnicode=true&characterEncoding=GB2312" ;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String query="select Name from suser order by id";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
String s=rs.getString("Name");
out.print(s+"<br>");
}
%>
</body>
</html>
我的数据库:root 19950506
一个数据库:myjava 表 suser Name为varchar
type Exception report
message An exception occurred processing JSP page /working/L1judge.jsp at line 11
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 /working/L1judge.jsp at line 11
8: Connection conn= DriverManager.getConnection(url);
9: Statement stmt=conn.createStatement();
10: String query="select Name from suser order by id";
11: ResultSet rs=stmt.executeQuery(query);
12: while(rs.next())
13: {
14: String s=rs.getString("Name"); 展开
1个回答
2015-06-25
展开全部
这段代码没问题, 就是这样写的.
把详细点的错误贴出来看下
把详细点的错误贴出来看下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询