| | |
| | | mysqlCenlint.userService = this.userService; |
| | | } |
| | | |
| | | /** |
| | | * sql 连接 |
| | | * @param sql |
| | | */ |
| | | public static void sqlConnect(String sql,Integer type){ |
| | | String driver = "com.mysql.cj.jdbc.Driver"; |
| | | String url = sqlConnect; //换成要连接的数据库信息 |
| | | String user = "root"; |
| | | String password = "zhba0728"; |
| | | Connection conn = null; |
| | | PreparedStatement ps = null; |
| | | try { |
| | | Class.forName ( driver ); |
| | | conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | if (!conn.isClosed ()) { |
| | | System.out.println ( "数据库连接成功:" ); |
| | | String sqls = sql; |
| | | ps = conn.prepareStatement ( sqls ); |
| | | //判断是否为修改,删除 |
| | | if (type==1){ |
| | | //修改删除 |
| | | ps.executeUpdate(); |
| | | }else { |
| | | //新增 |
| | | ps.execute(); |
| | | } |
| | | } |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace (); |
| | | }finally { |
| | | try { |
| | | ps.close(); |
| | | conn.close(); |
| | | } catch (SQLException throwables) { |
| | | throwables.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 连接mysql数据库 新增 |
| | | * @param sql |
| | | */ |
| | | public static void inster(String sql) { |
| | | try { |
| | | int ColumnCount; |
| | | //int RowCount; |
| | | String driver = "com.mysql.cj.jdbc.Driver"; |
| | | String url = sqlConnect; //换成要连接的数据库信息 |
| | | String user = "root"; |
| | | String password = "zhba0728"; |
| | | Class.forName ( driver ); |
| | | Connection conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | if (!conn.isClosed ()) { |
| | | System.out.println ( "数据库连接成功:" ); |
| | | String sqls = sql; //sql |
| | | PreparedStatement ps = conn.prepareStatement ( sqls ); |
| | | boolean execute = ps.execute(); |
| | | ps.close (); |
| | | conn.close (); |
| | | } |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace (); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace (); |
| | | } |
| | | sqlConnect(sql,2); |
| | | try { |
| | | Thread.sleep(300); |
| | | //对比 sql 字符串,如果是是往用户表里插入保安员数据,则调用公安审查接口 |
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param sql |
| | | */ |
| | | public static void update(String sql) { |
| | | try { |
| | | int ColumnCount; |
| | | //int RowCount; |
| | | String driver = "com.mysql.cj.jdbc.Driver"; |
| | | String url = sqlConnect; //换成要连接的数据库信息 |
| | | String user = "root"; |
| | | String password = "zhba0728"; |
| | | Class.forName ( driver ); |
| | | Connection conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | if (!conn.isClosed ()) { |
| | | System.out.println ( "数据库连接成功:" ); |
| | | String sqls = sql; //sql |
| | | PreparedStatement ps = conn.prepareStatement ( sqls ); |
| | | ps.executeUpdate(); |
| | | ps.close (); |
| | | conn.close (); |
| | | } |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace (); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace (); |
| | | } |
| | | sqlConnect(sql,1); |
| | | // try { |
| | | // int ColumnCount; |
| | | // //int RowCount; |
| | | // String driver = "com.mysql.cj.jdbc.Driver"; |
| | | // String url = sqlConnect; //换成要连接的数据库信息 |
| | | // String user = "root"; |
| | | // String password = "zhba0728"; |
| | | // Class.forName ( driver ); |
| | | // Connection conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | // if (!conn.isClosed ()) { |
| | | // System.out.println ( "数据库连接成功:" ); |
| | | // String sqls = sql; //sql |
| | | // PreparedStatement ps = conn.prepareStatement ( sqls ); |
| | | // ps.executeUpdate(); |
| | | // ps.close (); |
| | | // conn.close (); |
| | | // } |
| | | // } catch (ClassNotFoundException e) { |
| | | // e.printStackTrace (); |
| | | // } catch (SQLException e) { |
| | | // e.printStackTrace (); |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param sql |
| | | */ |
| | | public static void delete(String sql) { |
| | | try { |
| | | int ColumnCount; |
| | | //int RowCount; |
| | | String driver = "com.mysql.cj.jdbc.Driver"; |
| | | String url = sqlConnect; //换成要连接的数据库信息 |
| | | String user = "root"; |
| | | String password = "zhba0728"; |
| | | Class.forName ( driver ); |
| | | Connection conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | if (!conn.isClosed ()) { |
| | | System.out.println ( "数据库连接成功:" ); |
| | | String sqls = sql; //sql |
| | | PreparedStatement ps = conn.prepareStatement ( sqls ); |
| | | ps.executeUpdate(); |
| | | ps.close (); |
| | | conn.close (); |
| | | } |
| | | } catch (ClassNotFoundException e) { |
| | | e.printStackTrace (); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace (); |
| | | } |
| | | sqlConnect(sql,1); |
| | | // try { |
| | | // int ColumnCount; |
| | | // //int RowCount; |
| | | // String driver = "com.mysql.cj.jdbc.Driver"; |
| | | // String url = sqlConnect; //换成要连接的数据库信息 |
| | | // String user = "root"; |
| | | // String password = "zhba0728"; |
| | | // Class.forName ( driver ); |
| | | // Connection conn = (Connection) DriverManager.getConnection ( url, user, password ); |
| | | // if (!conn.isClosed ()) { |
| | | // System.out.println ( "数据库连接成功:" ); |
| | | // String sqls = sql; //sql |
| | | // PreparedStatement ps = conn.prepareStatement ( sqls ); |
| | | // ps.executeUpdate(); |
| | | // ps.close (); |
| | | // conn.close (); |
| | | // } |
| | | // } catch (ClassNotFoundException e) { |
| | | // e.printStackTrace (); |
| | | // } catch (SQLException e) { |
| | | // e.printStackTrace (); |
| | | // } |
| | | } |
| | | |
| | | /** |