标题:数据库连接问题
只看楼主
wolfcool
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2006-12-9
 问题点数:0 回复次数:7 
数据库连接问题

这代码到我的机子上就怎么运行不了啊
我是新手望知道的指点下,sqlserver应该没有问题我用asp可以连接成功
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=shop";

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 * from userinfo";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html

[此贴子已经被作者于2007-5-16 18:38:44编辑过]

搜索更多相关主题的帖子: 数据库 String sqlserver password 
2007-05-16 18:38
sxzxwxf22
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2007-3-7
得分:0 
把错误贴出来看看

2007-05-16 18:52
pity1115
Rank: 1
等 级:新手上路
威 望:2
帖 子:184
专家分:0
注 册:2006-9-15
得分:0 
是不是没有驱动包或者没有打补丁?

2007-05-16 20:23
wolfcool
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2006-12-9
得分:0 

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.testsql_jsp._jspService(testsql_jsp.java:86)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:150)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:71)
    java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Class.java:141)
    org.apache.jsp.testsql_jsp._jspService(testsql_jsp.java:47)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.

2007-05-16 23:28
支离破碎
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:737
专家分:0
注 册:2007-1-4
得分:0 


ClassNotFound不是说了类没找到吗?看你的驱动包是否在lib下,是否在classpath中

人生漂泊無依,有如浮萍菱花,隨水飄流,你会在我这里停留吗?
[url=http://51mynet.]http://51mynet.[/url]
2007-05-17 09:05
wolfcool
Rank: 1
等 级:新手上路
帖 子:102
专家分:0
注 册:2006-12-9
得分:0 
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.jj_jsp._jspService(jj_jsp.java:114)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
    com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
    com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
    com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
    com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
    com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    java.sql.DriverManager.getConnection(DriverManager.java:512)
    java.sql.DriverManager.getConnection(DriverManager.java:171)
    org.apache.jsp.jj_jsp._jspService(jj_jsp.java:61)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
2007-05-17 14:23
支离破碎
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:737
专家分:0
注 册:2007-1-4
得分:0 

SQLService的SP4补丁


人生漂泊無依,有如浮萍菱花,隨水飄流,你会在我这里停留吗?
[url=http://51mynet.]http://51mynet.[/url]
2007-05-17 15:05
yufeiyan
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-4
得分:0 
把数据库jdbc驱动的三个包应该放到工程的WEB-INF\lib目录下试试看
2007-05-20 20:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-139952-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.387041 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved