java 連結sql server 2000 問題

okone96發表於2007-04-23

java 連結sql server 2000 總結

Context envContext = (Context)initCtx.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/jieba");
conn = ds.getConnection();

執行後總是出現:

java.lang.NoSuchMethodError: com.microsoft.util.UtilDebug.setPrintWriter(Ljava/io/PrintWriter;)V
at com.microsoft.jdbc.base.BaseDriver.setupDebugging(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at com.hero.analysis.service.base.DBConnection.getConnection(DBConnection.java:41)
at com.hero.analysis.service.base.JDBCFacade.getDataSource(JDBCFacade.java:72)
at com.hero.analysis.service.base.JDBCFacade.(JDBCFacade.java:43)
at com.hero.analysis.dao.mysql.MysqlUserDAO.login(MysqlUserDAO.java:50)
at com.hero.analysis.service.UserBO.login(UserBO.java:27)
at com.hero.analysis.web.user.LoginAction.execute(LoginAction.java:39)
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:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.hero.analysis.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:121)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.hero.analysis.util.CheckLoginFilter.doFilter(CheckLoginFilter.java:90)
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(Thread.java:595)

跟著程式走了以下,確實沒有這個方法,鬱悶了一天

經過反覆除錯後發現有幾種可能造成這個原因

1.驅動程式的版本不對

2 .sql server 2000沒有打補丁 必須打補丁

3 .檢查sql server 2000 的驅動程式mssql.jar,msbase.jar,mssqlserver.jar,msutil.jar存放位置對不對,一般放在tomact/commen/lib下就可以,或放進class_path,或webinfo/lib下,一般情況下,放一個地方就可以了

4 .位置方對了還不行 那可以考慮jdbc驅動程式的版本對不對,如果你打了 sp2補丁 那麼也要用for sp2 driver

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/750220/viewspace-912034/,如需轉載,請註明出處,否則將追究法律責任。

相關文章