您的位置:程序门 -> 《程序员》杂志 -> 基本信息



mysql与jdbc的连接对象!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


mysql与jdbc的连接对象!
发表于:2007-12-19 14:26:06 楼主
java.sql.connection;
java,lang.string   strconn;
java.sql.preparedstatement   preparedstmt;
sql语句对象只能有以个,但可以很多个变量来应用。我不知道怎样应用。

发表于:2007-12-31 02:14:391楼 得分:0
public       vector       getallproduct(){  
                                connection       con       =       null;  
                                preparedstatement       ps       =       null;  
                                resultset       rs       =       null;  
                                vector       vec       =       new       vector();  
                                productrecordbean       prb       =       null;  
                                try{  
                                                class.forname("sun.jdbc.odbc.jdbcodbcdriver");  
                                                con       =       drivermanager.getconnection("jdbc:odbc:dsn_shop");  
                                                ps       =       con.preparestatement("select       *       from       table_product");  
                                                rs       =       ps.EXECutequery();  
                                                while(rs.next()){  
                                                                prb       =       new       productrecordbean();  
                                                                prb.setid(       rs.getint("id")       );  
                                                                prb.setname(       rs.getstring("name")       );  
                                                                prb.setprice(       rs.getdouble("price")       );  
                                                                prb.setquantity(       rs.getint("quantity")       );  
                                                                vec.add(prb);  
                                                }  
                                }catch(exception       e){  
                                                e.printstacktrace();  
                                }finally{  
                                                try{  
                                                                if(rs!=null)       rs.close();  
                                                                if(ps!=null)       ps.close();  
                                                                if(con!=null)       con.close();  
                                                }catch(exception       e){  
                                                                e.printstacktrace();  
                                                }  
                                }  
                                return       vec;  
                }  

给你参考下吧,
dsn_shop是数据源
发表于:2008-01-04 13:43:302楼 得分:0
我想说的是关于关闭rs,ps.con有没有一定的规则?也就是说他们的先后次序对程序的有没有印象呢?


快速检索

最新资讯
热门点击