diff --git a/testJDBC/JDBCDemo1/JDBCDemo1.iml b/testJDBC/JDBCDemo1/JDBCDemo1.iml new file mode 100644 index 0000000..b2c698e --- /dev/null +++ b/testJDBC/JDBCDemo1/JDBCDemo1.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/testJDBC/JDBCDemo1/lib/mysql-connector-java-8.0.11.jar b/testJDBC/JDBCDemo1/lib/mysql-connector-java-8.0.11.jar new file mode 100644 index 0000000..c3b5f70 Binary files /dev/null and b/testJDBC/JDBCDemo1/lib/mysql-connector-java-8.0.11.jar differ diff --git a/testJDBC/JDBCDemo1/src/com/msb/test1/TestJDBC.java b/testJDBC/JDBCDemo1/src/com/msb/test1/TestJDBC.java new file mode 100644 index 0000000..4ab3df6 --- /dev/null +++ b/testJDBC/JDBCDemo1/src/com/msb/test1/TestJDBC.java @@ -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(); + } + } + } +} diff --git a/testJDBC/testJDBC.iml b/testJDBC/testJDBC.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/testJDBC/testJDBC.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file