L
laozheng
Unregistered / Unconfirmed
GUEST, unregistred user!
原代码:
%@ page contentType="text/html;
charset=gb2312" %>
<%@ page info="database handler"%>
<!--导入结束-->
<html>
<head>
<title>
jdbctest
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Jdbc 连接到 Access 数据库的例子</h1>
<%
java.sql.Connection sqlCon;
//数据库连接对象
java.sql.Statement sqlStmt;
//SQL语句对象
java.sql.ResultSet sqlRst;
//结果集对象
java.lang.String strCon;
//数据库连接字符串
java.lang.String strSQL;
//SQL语句
//装载JDBC-ODBC驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//设置数据库连接字符串
strCon = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=user";
//数据库是一个Access文件,里面有一张表user,表里有userid和userpass两个字段
sqlCon = java.sql.DriverManager.getConnection(strCon,"jsdnfik","");
//创建SQL语句对象
sqlStmt = sqlCon.createStatement();
strSQL = "select * from user";
out.println(strSQL);
sqlRst = sqlStmt.executeQuery(strSQL);
//打印测试
if( sqlRst != null ){
out.println("一共有"+sqlRst.getRow()+"条记录");
while( sqlRst.next() ){
out.println("你的用户名字是:/t" + sqlRst.getString("username")+"<br>");
out.println("你的密码是:/t" + sqlRst.getString("password")+"<br>");
out.println("一共有"+sqlRst.getRow()+"条记录<br>");
}
out.println("一共有"+sqlRst.getRow()+"条记录");
}
sqlRst.close();
sqlCon.close();
%>
</body>
</html>
出错信息如下:
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: No suitable driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:795)
org.apache.jsp.test_jsp._jspService(test_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.sql.SQLException: No suitable driver
java.sql.DriverManager.getConnection(DriverManager.java:532)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.test_jsp._jspService(test_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
不知道是什么原因:请高手指点
%@ page contentType="text/html;
charset=gb2312" %>
<%@ page info="database handler"%>
<!--导入结束-->
<html>
<head>
<title>
jdbctest
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Jdbc 连接到 Access 数据库的例子</h1>
<%
java.sql.Connection sqlCon;
//数据库连接对象
java.sql.Statement sqlStmt;
//SQL语句对象
java.sql.ResultSet sqlRst;
//结果集对象
java.lang.String strCon;
//数据库连接字符串
java.lang.String strSQL;
//SQL语句
//装载JDBC-ODBC驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//设置数据库连接字符串
strCon = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=user";
//数据库是一个Access文件,里面有一张表user,表里有userid和userpass两个字段
sqlCon = java.sql.DriverManager.getConnection(strCon,"jsdnfik","");
//创建SQL语句对象
sqlStmt = sqlCon.createStatement();
strSQL = "select * from user";
out.println(strSQL);
sqlRst = sqlStmt.executeQuery(strSQL);
//打印测试
if( sqlRst != null ){
out.println("一共有"+sqlRst.getRow()+"条记录");
while( sqlRst.next() ){
out.println("你的用户名字是:/t" + sqlRst.getString("username")+"<br>");
out.println("你的密码是:/t" + sqlRst.getString("password")+"<br>");
out.println("一共有"+sqlRst.getRow()+"条记录<br>");
}
out.println("一共有"+sqlRst.getRow()+"条记录");
}
sqlRst.close();
sqlCon.close();
%>
</body>
</html>
出错信息如下:
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: No suitable driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:795)
org.apache.jsp.test_jsp._jspService(test_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.sql.SQLException: No suitable driver
java.sql.DriverManager.getConnection(DriverManager.java:532)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.test_jsp._jspService(test_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
不知道是什么原因:请高手指点