Topic: 请大家帮解决一下这是什么原因!!! |
Print this page |
1.请大家帮解决一下这是什么原因!!! | Copy to clipboard |
Posted by: bj_lwt2000 Posted on: 2005-05-18 14:44 package db; import java.sql.*; //import java.util.*; //import javax.sql.*; //import javax.naming.*; /** * @author Administrator * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class Voddb { private String dbUrl="jdbc:mysql://localhost:3306/good"; private String dbUser="root"; private String dbPwd="1234"; public Voddb() throws Exception{ Class.forName("com.mysql.jdbc.Driver"); } public Connection getConnection() throws Exception{ return DriverManager.getConnection( dbUrl,dbUser,dbPwd); } public void closeConnection(Connection con){ try{ if(con!=null) con.close(); }catch(Exception e){ e.printStackTrace() ; } } public void closePrepStmt(PreparedStatement prepStmt){ try{ if(prepStmt!=null) prepStmt.close(); }catch(Exception e){ e.printStackTrace() ; } } public void closeResultSet(ResultSet rs){ try{ if(rs!=null) rs.close(); }catch(Exception e){ e.printStackTrace() ; } } } |
2.Re:请大家帮解决一下这是什么原因!!! [Re: bj_lwt2000] | Copy to clipboard |
Posted by: bj_lwt2000 Posted on: 2005-05-18 14:46 package temp; import db.*; import java.sql.*; import java.util.*; /** * @author Administrator * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class List { private ArrayList info; List() throws Exception{ Connection con=null; PreparedStatement prepStmt=null; ResultSet rs=null; info=new ArrayList(); try{ con=Voddb.getConnection(); /////这里发生错误!!!!!!! String selectStatement="select *" + "from info"; prepStmt=con.prepareStatement( selectStatement); rs=prepStmt.executeQuery(); while(rs.next()){ Getlist bd=new Getlist(rs.getString(1),rs.getString(2),rs.getInt(3),rs.getString(4)); info.add(bd); } }catch(Exception e){ e.printStackTrace() ; } } } |
3.Re:请大家帮解决一下这是什么原因!!! [Re: bj_lwt2000] | Copy to clipboard |
Posted by: bj_lwt2000 Posted on: 2005-05-18 14:47 第一个是连接数据库。 第二个中在连接库时发生错误。是调用不对吗。 |
4.Re:请大家帮解决一下这是什么原因!!! [Re: bj_lwt2000] | Copy to clipboard |
Posted by: why Posted on: 2005-05-18 21:55 Please show us the stack trace. Why not add a main method in Voddb.java and test opening a connection first? BTW, I would usually use Class.forName("com.mysql.jdbc.Driver").newInstance(); |
5.Re:请大家帮解决一下这是什么原因!!! [Re: bj_lwt2000] | Copy to clipboard |
Posted by: ecsoftcn Posted on: 2005-07-08 09:03 Voddb 是一个普通类,你在第二个中直接调用con=Voddb.getConnection(); 方法得到数据库连接,但是在第一个中你并没有声明该方法是static的,试问非静态方法能用类(不是对象)直接调用么?? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |