Java JDBC Demo
try {
//1、获得驱动
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try{
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
String user = "root";
String password = "xxx";
onnection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/sbtest?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai",user,password);
String sql = "insert into `user` VALUE(?,?,?,?)";
//创建statement
statement= connection.prepareStatement(sql);
statement.setInt(1, 222);
statement.setString(2, "lisi");
statement.setInt(3, 32);
statement.setString(4, "222@163.com");
statement.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
//....关闭相关连接
}
JDBC参数
持续更新…
URL参数 | 作用 | 中文解释 | 版本 |
---|---|---|---|
user | |||
password | |||
characterEncoding | 连接 | 指定与服务器连接的字符集 | |
allowPublicKeyRetrieval | 安全 | 直接从服务器获取RSA公钥 | |
useSSL | 安全 | 已弃用。使用SSL与服务器通信。 | |
serverTimezone | 连接 | 指定时区 |
停止更新
关于参数及使用:见我另一篇【connectorj测试】