做到c3p0,最基本的查询,为啥报了错
来自课程:蛋糕店(Jsp、Servlet网上商城)
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@68f585a3 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
加不加入buildpath都会报错
源码:
package learnsth;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class Test {
public static void main(String[] args) throws Exception {
DataSource ds = new ComboPooledDataSource();//使用c3p0的数据源
Connection con = ds.getConnection();
PreparedStatement ps = con.prepareStatement("select * from goods");
ResultSet rs = ps.executeQuery();
while(rs.next()) {
System.out.println(rs.getString("name"));
}
rs.close();
ps.close();
con.close();
}
}

