jsp的数据库连接问题,求教,急!!!!!!!!!!!!!!!!!!!!!
<%@ page language= "java " import= "java.util.* " pageEncoding= "UTF-8 "%>
<%@ page import= "java.sql.* "%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<base href= " <%=basePath%> ">
<title> My JSP 'sqlconn.jsp ' starting page </title>
<meta http-equiv= "pragma " content= "no-cache ">
<meta http-equiv= "cache-control " content= "no-cache ">
<meta http-equiv= "expires " content= "0 ">
<meta http-equiv= "keywords " content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "This is my page ">
<!--
<link rel= "stylesheet " type= "text/css " href= "styles.css ">
-->
</head>
<body>
<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://172.19.140.222:1433;DatabaseName=pubs ";
//pubs为你的数据库的
String user= "sa ";
String password= "123 ";
//Connection conn= DriverManager.getConnection(url,user,password);
//Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
%>
This is my JSP page. <BR> <%=url%> <br>
</body>
</html>
报错:
type Exception report
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:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.sqlconn_jsp._jspService(org.apache.jsp.sqlconn_jsp:102)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.sql.SQLException: No suitable driver
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.sqlconn_jsp._jspService(org.apache.jsp.sqlconn_jsp:86)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.7 logs.
[解决办法]
检查一下你的sql jdbc 的驱动安装正确没有,肯定是出在这个问题上了
请按如下提示进行检查一下:
安装在D盘的情况:
CLASSPATH %JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;D:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;
JAVA_HOME
D:\Program Files\Java\jdk1.5.0_08
path
%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\Wbem
----------------------------------------
安装在c盘的情况:
CLASSPATH %JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;
JAVA_HOME
C:\Program Files\Java\jdk1.5.0_08
path
%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\Wbem
//-------------------------------------------------------------------------
JSP 数据库开发配置说明:
1.Microsoft Sql Server 2000 标准版的安装;
2.Microsoft sql server 2000 sp3补丁的安装;
3:sql server 2000 JDBC Driver 的安装,而且在sql 运行的状态下安装;
4.配置系统环境变量:
CLASSPATH:
%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
[解决办法]
jdbc配置问题
[解决办法]
是你数据库驱动的问题
最好把库文件放到web应用目录下的lib里面
[解决办法]
需要配置环境变量的,还有就是要学会看报错信息呀
root cause
java.sql.SQLException: No suitable driver
提示出让你看看jdbc了估计如楼上所说。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html