[code]
public static Connection getDB2Connection() throws SQLException {
String DBDriver = "com.ibm.db2.jcc.DB2Driver";
String url = "jdbc:db2://localhost:6789/feiyang";
try {
Class.forName(DBDriver);
}catch (ClassNotFoundException ex) {
ex.printStackTrace(System.err);
}
return DriverManager.getConnection(url);
}
Connection conn = getDB2Connection();
[/code]
错误如下:
[code]
net.ConnectException:打开端口 6,789 上服务器 localhost/127.0.0.1 的套接字时出错,消息为:Connection refused: connect。
at com.ibm.db2.jcc.b.yb.a(yb.java:375)
at com.ibm.db2.jcc.b.yb.<init>(yb.java:76)
at com.ibm.db2.jcc.b.a.v(a.java:254)
at com.ibm.db2.jcc.b.b.a(b.java:1669)
at com.ibm.db2.jcc.c.p.a(p.java:350)
at com.ibm.db2.jcc.c.p.<init>(p.java:404)
at com.ibm.db2.jcc.b.b.<init>(b.java:256)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:163)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at edu.buptsse.pub.db.DBManager.getDB2Connection(DBManager.java:78)
at edu.buptsse.samplejspbean.DBHelper.getConnection(DBHelper.java:17)
at edu.buptsse.samplejspbean.UserBean.queryUser(UserBean.java:61)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:108)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at edu.buptsse.pub.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.ibm.db2.jcc.b.bb.run(bb.java:34)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.db2.jcc.b.yb.a(yb.java:369)
... 36 more
[/code]
哪位大侠能给我解释一下JDBC驱动应该如何加载,然后代码哪里有错啊?
2 个解决方案
#1
有没有人,帮帮忙啊!!!!
#2
用户名和密码都没有怎么连啊.真是的!
#1
有没有人,帮帮忙啊!!!!
#2
用户名和密码都没有怎么连啊.真是的!