1. 程式人生 > >資料庫操作-c3p0和mysql5.1.6

資料庫操作-c3p0和mysql5.1.6

c3p0和mysql5.1.6   jar包下載地址:http://download.csdn.net/download/qq_35131940/10258327

c3p0使用需要注意的幾點:

1、配置檔案的名字的是c3p0-config

2、配置好後,static ComboPooledDataSource dataSource=new ComboPooledDataSource("mysql");

dataSource.getConnection();這就可以獲得一個連線了,超級方便好用


mysql5.1.6使用注意事項:

一開始我直接下載的是最新版本的jar包,就報

Connections could not be acquired from the underlying database!

所以我就換成了5.1.6版本的mysql,正常執行

注意操作資料庫的PrepareStatement有兩個執行方法:

executeQuery();用來返回結果集

executeUpdate();用來執行更新

千萬要分開用,下面是資料操作的方便方法。


資料庫操作簡記:

sql="insert into user values(2,'sdfsd')"

conn.prepareStatement(sql);

pst.executeUpdate();

pst.close();

conn.close();