| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 845 人关注过本帖
标题:高手帮帮忙!
取消只看楼主 加入收藏
yq6780
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-10-17
收藏
 问题点数:0 回复次数:5 
高手帮帮忙!
学习struts阶段,数据库总是报错,在学校就没事,

错误信息:
at java.sql.DriverManager.getConnection(DriverManager.java:512)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at db.DBHelper.getConnection(DBHelper.java:18)

at dao.DAOHelperUser.login(DAOHelperUser.java:19)

at action.UserAction.login(UserAction.java:26)
我的代码:
package db;

import java.sql.*;

public class DBHelper {
private static Connection conn = null;
private static String url = null;
private static String serverName = null;
private static String portNumber = null;
private static String databaseName = null;
private static String uid = null;
private static String pwd = null;
public DBHelper() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
private static String getConnectionUrl()
{
url = "jdbc:microsoft:sqlserver://";
serverName = "127.0.0.1";
portNumber = "1433";
databaseName = "test";
uid = "sa";
pwd = "";

return url + serverName + ":" + portNumber + ";databaseName=" + databaseName + ";";
}

public static Connection getConnection()
{
try {
conn = DriverManager.getConnection(getConnectionUrl(),uid,pwd);
} catch (SQLException ex) {
ex.printStackTrace();
}
if ( conn != null )
{
System.out.println("连接成功");
}
return conn;
}
}
总报错,在学校就没事。高手们帮看看阿。。
搜索更多相关主题的帖子: 数据库 信息 private package public 
2007-07-10 12:51
yq6780
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-10-17
收藏
得分:0 
谢谢,谢谢。
可是还是不行的。。。
代码应该没问题啊,像你那样写,我也写了N次了。。。
在学校的机器上就能跑。
2007-07-10 15:53
yq6780
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-10-17
收藏
得分:0 
都打过的,用桥连连的上。。。
2007-07-10 16:06
yq6780
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-10-17
收藏
得分:0 
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)

at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)

at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)

at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)

at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)

at java.sql.DriverManager.getConnection(DriverManager.java:512)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at db.DB.getConnection(DB.java:17)

at dao.DAO.login(DAO.java:14)

at action.loginAction.login(loginAction.java:24)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)

at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)

at java.lang.Thread.run(Thread.java:534)

这样的。

2007-07-10 16:15
yq6780
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-10-17
收藏
得分:0 

不行,而且调试,连接那是没报异常,可是是NULL,用桥连的上。。。


exception

javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NullPointerException
dao.DAO.login(DAO.java:16)
action.loginAction.login(loginAction.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
2007-07-10 16:40
yq6780
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-10-17
收藏
得分:0 
是混合,我都把数据库,卸了装,装了卸,好几次了。。。
2007-07-10 17:00
快速回复:高手帮帮忙!
数据加载中...
 
   



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

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