数据库操作-c3p0和mysql5.1.6

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35131940/article/details/79368398

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();




猜你喜欢

转载自blog.csdn.net/qq_35131940/article/details/79368398