只需要mysql的驱动包:包名为:mysql-connector-java-5.1.37-bin.jar
源码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import org.junit.Test;
public class JdbcMysql {
@Test
public void connection() throws Exception{
String username = "root";
String password = "root";
String url = "jdbc:mysql://localhost:3306/exam?characterEncoding=utf-8";
String sql = "UPDATE s_cust SET cust_name=? WHERE cid = ? ";
/模闭/加载mysql的驱动类,获得连接,获取SQL的预编译,设置参数,迅颂执行亩码郑SQL语句
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, username, password);
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, "北京");
ps.setInt(2, 6);
ps.execute();
ps.close();
con.close();
}
}
commons-dbcp-1.4.jar
commons-pool-1.5.6.jar
主流数据库连接池之一(DBCP、c3p0、proxool),单空兆独使用弊亏好DBCP需要使用commons-dbpc.jar、commons-collections.jar、commons-pool.jar三个包