| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 800 人关注过本帖
标题:[求助]Struts连接数据库出错!
只看楼主 加入收藏
xhdwell
Rank: 1
等 级:新手上路
帖 子:124
专家分:0
注 册:2006-5-15
收藏
 问题点数:0 回复次数:2 
[求助]Struts连接数据库出错!

我的struts-config.xml是这样配置的!
<data-sources >
<data-source key="DATA_SOURCE" type="org.apache.struts.util.GenericDataSource">
<set-property property="minCount" value="" />
<set-property property="password" value="sa" />
<set-property property="maxCount" value="" />
<set-property property="user" value="sa" />
<set-property property="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<set-property property="description" value="datasource for strutstest" />
<set-property property="url" value="jdbc:microsoft:sqlserver://F9BBE496C1104BD:1433;DatabaseName=LoginTest" />
<set-property property="autoCommit" value="false" />
<set-property property="readOnly" value="false" />
<set-property property="loginTimeout" value="" />
</data-source>
在Action中是这样连接的:
ServletContext context = this.servlet.getServletContext();

DataSource ds=(DataSource)context.getAttribute("DATA_SOURCE");
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try {
conn=ds.getConnection();
stmt=conn.createStatement();
String sql="select * from usertable";
rs=stmt.executeQuery(sql);
但服务器提示出错!
严重: Initializing application data source DATA_SOURCE
java.sql.SQLException: open: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.apache.struts.legacy.GenericDataSource.open(GenericDataSource.java:735)
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:1085)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:472)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3917)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4201)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
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:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
2006-10-27 20:08:16 org.apache.catalina.core.ApplicationContext log
信息: Marking servlet action as unavailable
2006-10-27 20:08:16 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /StrutsTest threw load() exception
javax.servlet.UnavailableException: Initializing application data source DATA_SOURCE
at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:1091)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:472)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3917)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4201)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
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:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
是什么原因啊~~谁能帮帮我!
struts-legacy.jar我已经在lib文件夹里了!

搜索更多相关主题的帖子: property 数据库 Struts value 
2006-10-27 20:28
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
一看就知道没有把SQL SERVER驱动包放进LIB,导致了java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver

可惜不是你,陪我到最后
2006-10-28 11:36
xhdwell
Rank: 1
等 级:新手上路
帖 子:124
专家分:0
注 册:2006-5-15
收藏
得分:0 

斑竹厉害啊~~现在搞定了~~惭愧!


坚持自己的选择!向着理想迈出了第一步!
2006-10-28 16:53
快速回复:[求助]Struts连接数据库出错!
数据加载中...
 
   



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

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