parent
a1fe420b1a
commit
29e0641a3b
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="mysql-connector-java-8.0.11" level="project" />
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
@ -0,0 +1,42 @@
|
||||
package com.msb.test1;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class TestJDBC {
|
||||
public static void main(String[] args) {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
|
||||
try {
|
||||
// 选择数据库
|
||||
// Driver driver = new com.mysql.cj.jdbc.Driver();
|
||||
// DriverManager.registerDriver(driver);
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
// 建立连接
|
||||
String url = "jdbc:mysql://127.0.0.1:3306/mydb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";
|
||||
String user = "root";
|
||||
String password = "Fnst1234";
|
||||
connection = DriverManager.getConnection(url, user, password);
|
||||
|
||||
// 执行sql
|
||||
statement = connection.createStatement();
|
||||
String sql = "insert into dept values (51, '助教部', '北京')";
|
||||
int rows = statement.executeUpdate(sql);
|
||||
System.out.println("影响行数据:" + rows);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (statement != null) {
|
||||
statement.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
Loading…
Reference in new issue