当前位置: 代码迷 >> Java Web开发 >> 数据库连接成功,执行语句失败(配置win7+sqlserver2000+myeclipse8.5+tomcat6.0 ),该如何处理
  详细解决方案

数据库连接成功,执行语句失败(配置win7+sqlserver2000+myeclipse8.5+tomcat6.0 ),该如何处理

热度:10613   发布时间:2013-02-25 21:21:59.0
数据库连接成功,执行语句失败(配置win7+sqlserver2000+myeclipse8.5+tomcat6.0 )
package lwl.model;

import java.sql.*;
public class GoodsBeanBO {

private ResultSet rs = null;
private Connection ct = null;
private PreparedStatement ps = null;

//根据一个商品的货物Id,得到货物具体信息的函数
public GoodsBean getGoodsBean(String id){

GoodsBean gb = new GoodsBean();
try {
ct = new ConnDB().getConn();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("数据库连接失败");
}finally{
this.close();
}
try {
ps = ct.prepareStatement("select * from goods where goodsId=?");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("ps = ct.prepareStatement('select * from goods where goodsId=?')执行失败");
}finally{
this.close();
}
try {
ps.setString(1, id);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println(" ps.setString(1, id);执行失败");
}finally{
this.close();
}
try {
rs = ps.executeQuery();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("rs = ps.executeQuery();执行失败");
}finally{
this.close();
}
try{
if(rs.next()){
gb.setGoodsId(rs.getInt(1));
gb.setGoodsName(rs.getString(2));
gb.setGoodsIntro(rs.getString(3));
gb.setGoodsPrice(rs.getFloat(4));
gb.setGoodsNum(rs.getInt(5));
gb.setPublisher(rs.getString(6));
gb.setPhoto(rs.getString(7));
gb.setType(rs.getString(8));
}
}catch(Exception ex){
ex.printStackTrace();
System.out.println("rs.next()执行失败");

}finally{
this.close();
}
return gb;
}
public void close(){
try{
if(rs!=null){
rs.close();
rs = null;
}
if(ps!=null){
ps.close();
ps = null;
}
if(ct!=null){
ct.close();
ct = null;
}

}catch(Exception ex){
ex.printStackTrace();
}
}
}
2012-4-25 23:09:14 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Users\lwl\AppData\Local\Genuitec\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin
2012-4-25 23:09:15 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2012-4-25 23:09:15 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 2031 ms
2012-4-25 23:09:15 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-4-25 23:09:15 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.35
2012-4-25 23:09:15 org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2012-4-25 23:09:16 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2012-4-25 23:09:16 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2012-4-25 23:09:16 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory wxgww
2012-4-25 23:09:17 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-4-25 23:09:18 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2012-4-25 23:09:18 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/94 config=null
  相关解决方案