tomcat 7.0
SQLServer2008
按照配置在tomcat7.0的lib和项目的WEB-INF\lib里加载了sqljdbc4.jar,但连接不了
这是代码部分:
<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Connection con=null;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver ").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB";
String user="sa";
String password="sqlserver2008";
con=DriverManager.getConnection(url,user,password);
out.println("database connection success.");
%>
</body>
</html>
一下是报错部分:
严重: Servlet.service() for servlet [jsp] in context with path [/DBconnection] threw exception [An exception occurred processing JSP page /Connection.jsp at line 7
4: <body>
5: <%
6: Connection con=null;
7: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver ").newInstance();
8: String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB";
9: String user="sa";
10: String password="sqlserver2008";
Stacktrace:] with root cause
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.jsp.Connection_jsp._jspService(Connection_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
求大神帮忙解惑啊
21 个解决方案
#1
没有添加 sqlserver 的 jdbc 的 jar包 吧
百度搜索 msbase.jar mssqlserver.jar msutil.jar
或 jtds-1.2.5.jar
百度搜索 msbase.jar mssqlserver.jar msutil.jar
或 jtds-1.2.5.jar
#2
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver ").newInstance();
"SQLServerDriver”是不是多空格了啊?
"SQLServerDriver”是不是多空格了啊?
#3
正解。
#4
2楼正解
#5
你把JAR包放到LIB下了 你看有没有自动加载到你工程里面。。这个错误就是明显没加载上驱动。。
#6
缺少mssqlserver.jar,msbase.jar
#7
LZ的开发环境版本都好高啊
#8
我新手,配置的比较晚。
重新配置过后 ,工程里有mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar包,异常说没有合适的驱动,怎么回事,难道有其他什么地方有问题吗?操作系统问题吗?还是?
严重: Servlet.service() for servlet [jsp] in context with path [/DBConnection] threw exception [javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB] with root cause
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.apache.jsp.connection_jsp._jspService(connection_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
重新配置过后 ,工程里有mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar包,异常说没有合适的驱动,怎么回事,难道有其他什么地方有问题吗?操作系统问题吗?还是?
严重: Servlet.service() for servlet [jsp] in context with path [/DBConnection] threw exception [javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB] with root cause
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.apache.jsp.connection_jsp._jspService(connection_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
#9
工程里有mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar包,在运行异常说没有合适的驱动,怎么回事,难道有其他什么地方有问题吗?操作系统问题吗?
#10
mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar???????????
为什么会有这么多JAR呢?
你现在用的是什么数据就放什么jar包,其余的删除了!
另外,如果jar包没有导入成功,当你手动输入com.microsoft.sqlserver.jdbc.SQLServerDriver这句话时,当你打点会自动提示后面的代码(不在双引号中)。
还有一个问题,你直接进入数据库操作看看是否可以,我怀疑端口有没有打开或者访问权限什么的。
最后,我说的那个空格你去掉了吗?
为什么会有这么多JAR呢?
你现在用的是什么数据就放什么jar包,其余的删除了!
另外,如果jar包没有导入成功,当你手动输入com.microsoft.sqlserver.jdbc.SQLServerDriver这句话时,当你打点会自动提示后面的代码(不在双引号中)。
还有一个问题,你直接进入数据库操作看看是否可以,我怀疑端口有没有打开或者访问权限什么的。
最后,我说的那个空格你去掉了吗?
#11
空格已经去掉了,连接sql2008要用到哪个jar,这个一直不知道,书上用的sql2000,2008用哪个....这里真心求教,是不是就在这里导致一直无法连接上,在目前打点后会自动提示代码的。数据库的端口都打开了,那个动态端口要打开吗?另外就是,用JAVA连接可以正常连接上。就是JSP连接异常。
#12
连接sql2008要用到哪个jar ?
sqljdbc4.jar 这一个就OK
sqljdbc4.jar 这一个就OK
#13
用sqljdbc4.jar连接sqlserver2008,连接字符串应该用jdbc:sqlserver://,里面没有microsoft,老版本驱动连接才那样写
#14
果然如LS所言极是啊,踏破铁鞋无觅处得来全不费工夫,感慨学的不如更新的快。那么又有个问题了,就是java运行的时候,用jdbc:microsoft:sqlserver://就可以连接;而JSP+tomcat时就用jdbc:sqlserver://?怎么回事?
#15
明白了都是用jdbc:microsoft:sqlserver://,谢谢了
#16
SQL 2008的话,是不是只是把sqljdbc4.jar这个文件放到TOMCAT 的Lib文件夹下就行了?用不用配制环境变量?
#17
还是没有个权威的结果,我百度了好久,结果蛋碎了一地
#18
终于搞定了,根本就不需要配置环境变量,classpath本是class所在的路径,sqljdbc4.jar根本就不可能认识,解压后或许还行吧,最简单的办法就是在当前项目中把sqljdbc4.jar包含进来,亲测刚成功。方法:右击项目名称--buildPath--configure buildpath--Add External JARs-把sqljdbc4.jar包含进来就ok
jsp代码:
数据库配置百度就可以解决了
jsp代码:
<%@ page language="java" import="java.util.*,java.sql.*"
pageEncoding="UTF-8"%>
<%
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 'index.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>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rst = null;
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433; DatabaseName=BookSystem";
String user = "sa";
String password = "pass";
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
System.out.println("成功连接上数据库!");
stmt = conn.createStatement();
rst = stmt.executeQuery("Select * from Books");
while (rst.next()) {
System.out.println(rst.getString(3));
}
rst.close();
stmt.close();
conn.close();
%>
</body>
</html>
数据库配置百度就可以解决了
#19
SQL2005版本以上的 就是sqljdbc4.jar就可以了吧。。
#20
type Exception report
message
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 /MyJsp.jsp at line 11
8: String strConn="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wsdc";
9: String strUser="zhujian";
10: String strPassword="0951148";
11: conn=DriverManager.getConnection("strConn","strUser","strPassword");
12: out.println("JDBC专用驱动程序连接数据库成功!");
13: %>
14: </html>
谁帮我看一下啊 前几天还能连数据库的 今天早上就有问题了
message
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 /MyJsp.jsp at line 11
8: String strConn="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wsdc";
9: String strUser="zhujian";
10: String strPassword="0951148";
11: conn=DriverManager.getConnection("strConn","strUser","strPassword");
12: out.println("JDBC专用驱动程序连接数据库成功!");
13: %>
14: </html>
谁帮我看一下啊 前几天还能连数据库的 今天早上就有问题了
#21
一楼正解啊!
#1
没有添加 sqlserver 的 jdbc 的 jar包 吧
百度搜索 msbase.jar mssqlserver.jar msutil.jar
或 jtds-1.2.5.jar
百度搜索 msbase.jar mssqlserver.jar msutil.jar
或 jtds-1.2.5.jar
#2
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver ").newInstance();
"SQLServerDriver”是不是多空格了啊?
"SQLServerDriver”是不是多空格了啊?
#3
正解。
#4
2楼正解
#5
你把JAR包放到LIB下了 你看有没有自动加载到你工程里面。。这个错误就是明显没加载上驱动。。
#6
缺少mssqlserver.jar,msbase.jar
#7
LZ的开发环境版本都好高啊
#8
我新手,配置的比较晚。
重新配置过后 ,工程里有mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar包,异常说没有合适的驱动,怎么回事,难道有其他什么地方有问题吗?操作系统问题吗?还是?
严重: Servlet.service() for servlet [jsp] in context with path [/DBConnection] threw exception [javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB] with root cause
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.apache.jsp.connection_jsp._jspService(connection_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
重新配置过后 ,工程里有mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar包,异常说没有合适的驱动,怎么回事,难道有其他什么地方有问题吗?操作系统问题吗?还是?
严重: Servlet.service() for servlet [jsp] in context with path [/DBConnection] threw exception [javax.servlet.ServletException: java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB] with root cause
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.apache.jsp.connection_jsp._jspService(connection_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
#9
工程里有mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar包,在运行异常说没有合适的驱动,怎么回事,难道有其他什么地方有问题吗?操作系统问题吗?
#10
mssqlserver.jar,msbase.jar,msutil.jar,sqljdbc4.jar???????????
为什么会有这么多JAR呢?
你现在用的是什么数据就放什么jar包,其余的删除了!
另外,如果jar包没有导入成功,当你手动输入com.microsoft.sqlserver.jdbc.SQLServerDriver这句话时,当你打点会自动提示后面的代码(不在双引号中)。
还有一个问题,你直接进入数据库操作看看是否可以,我怀疑端口有没有打开或者访问权限什么的。
最后,我说的那个空格你去掉了吗?
为什么会有这么多JAR呢?
你现在用的是什么数据就放什么jar包,其余的删除了!
另外,如果jar包没有导入成功,当你手动输入com.microsoft.sqlserver.jdbc.SQLServerDriver这句话时,当你打点会自动提示后面的代码(不在双引号中)。
还有一个问题,你直接进入数据库操作看看是否可以,我怀疑端口有没有打开或者访问权限什么的。
最后,我说的那个空格你去掉了吗?
#11
空格已经去掉了,连接sql2008要用到哪个jar,这个一直不知道,书上用的sql2000,2008用哪个....这里真心求教,是不是就在这里导致一直无法连接上,在目前打点后会自动提示代码的。数据库的端口都打开了,那个动态端口要打开吗?另外就是,用JAVA连接可以正常连接上。就是JSP连接异常。
#12
连接sql2008要用到哪个jar ?
sqljdbc4.jar 这一个就OK
sqljdbc4.jar 这一个就OK
#13
用sqljdbc4.jar连接sqlserver2008,连接字符串应该用jdbc:sqlserver://,里面没有microsoft,老版本驱动连接才那样写
#14
果然如LS所言极是啊,踏破铁鞋无觅处得来全不费工夫,感慨学的不如更新的快。那么又有个问题了,就是java运行的时候,用jdbc:microsoft:sqlserver://就可以连接;而JSP+tomcat时就用jdbc:sqlserver://?怎么回事?
#15
明白了都是用jdbc:microsoft:sqlserver://,谢谢了
#16
SQL 2008的话,是不是只是把sqljdbc4.jar这个文件放到TOMCAT 的Lib文件夹下就行了?用不用配制环境变量?
#17
还是没有个权威的结果,我百度了好久,结果蛋碎了一地
#18
终于搞定了,根本就不需要配置环境变量,classpath本是class所在的路径,sqljdbc4.jar根本就不可能认识,解压后或许还行吧,最简单的办法就是在当前项目中把sqljdbc4.jar包含进来,亲测刚成功。方法:右击项目名称--buildPath--configure buildpath--Add External JARs-把sqljdbc4.jar包含进来就ok
jsp代码:
数据库配置百度就可以解决了
jsp代码:
<%@ page language="java" import="java.util.*,java.sql.*"
pageEncoding="UTF-8"%>
<%
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 'index.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>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rst = null;
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433; DatabaseName=BookSystem";
String user = "sa";
String password = "pass";
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
System.out.println("成功连接上数据库!");
stmt = conn.createStatement();
rst = stmt.executeQuery("Select * from Books");
while (rst.next()) {
System.out.println(rst.getString(3));
}
rst.close();
stmt.close();
conn.close();
%>
</body>
</html>
数据库配置百度就可以解决了
#19
SQL2005版本以上的 就是sqljdbc4.jar就可以了吧。。
#20
type Exception report
message
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 /MyJsp.jsp at line 11
8: String strConn="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wsdc";
9: String strUser="zhujian";
10: String strPassword="0951148";
11: conn=DriverManager.getConnection("strConn","strUser","strPassword");
12: out.println("JDBC专用驱动程序连接数据库成功!");
13: %>
14: </html>
谁帮我看一下啊 前几天还能连数据库的 今天早上就有问题了
message
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 /MyJsp.jsp at line 11
8: String strConn="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wsdc";
9: String strUser="zhujian";
10: String strPassword="0951148";
11: conn=DriverManager.getConnection("strConn","strUser","strPassword");
12: out.println("JDBC专用驱动程序连接数据库成功!");
13: %>
14: </html>
谁帮我看一下啊 前几天还能连数据库的 今天早上就有问题了
#21
一楼正解啊!