jdbc 连接sqlserver2008 登录失败 连不上数据库

sendoh_akira 2011-03-09 09:15:47

package common;

import java.sql.*;

public class DBUtil
{
private static String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

private static String url = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=BookShop";

private static String userId = "sa";

private static String password = "sa";

private static Connection con = null;

private static Statement stmt = null;

private static ResultSet rs = null;



public static int ExecuteUpdate(String sql) throws Exception
{
int rows = 0;

try
{
Class.forName(driverName);

con = DriverManager.getConnection(url, "sa", "sa");

stmt = con.createStatement();

rows = stmt.executeUpdate(sql);
}
catch(Exception ex)
{
System.out.print(ex.getMessage());
}

return rows;
}

public static ResultSet ExecuteQuery(String sql) throws Exception
{


try
{
Class.forName(driverName).newInstance();

con = DriverManager.getConnection(url, "sa", "sa");

stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

rs = stmt.executeQuery(sql);
}
catch(Exception ex)
{
System.out.print(ex.getMessage());
}

return rs;
}
}



上面是部分代码
我的其他工程连接数据库是能连接上的 同样是jdbc 连接的用户也是一样的

这个工程我找不出错 但是连接不上数据库
...全文
138 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
轩____ 2011-03-09
用户 'sa' 登录失败。用户 'sa' 登录失败。用户 'sa' 登录失败。用户 'sa' 登录失败。用户 'sa' 登录失败。用户 'sa' 登录失败。用户 'sa' 登录失败。2011-3-9 9:09:49 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.BookType_jsp._jspService(BookType_jsp.java:239)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at servlet.BookType.doGet(BookType.java:90)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
An exception occurred processing JSP page /BookType.jsp at line 48

45: // 鍥句功淇℃伅闆嗗悎
46: ResultSet rsBook1 = (ResultSet)request.getAttribute("RSBOOK1");
47:
48: while(rsBook1.next())
49: {
50: // 鍥句功缂栧彿
51: String bookId = rsBook1.getString("BookId");


Stacktrace:
回复
zn85600301 2011-03-09
贴异常信息
回复
runer 2011-03-09
把上述代码执行的日志信息贴出来
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2011-03-09 09:15
社区公告
暂无公告