| New file |
| | |
| | | package org.springblade.modules.FTP; |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.sql.Connection; |
| | | import java.sql.DriverManager; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.SQLException; |
| | | |
| | | public class MysqlCenlint { |
| | | |
| | | /** |
| | | * 连接mysql数据库 新增 |
| | | * @param sql |
| | | */ |
| | | public static void inster(String sql) { |
| | | try { |
| | | int ColumnCount; |
| | | //int RowCount; |
| | | String driver = "com.mysql.jdbc.Driver"; |
| | | String url = "jdbc:mysql://223.82.109.183:2083/zhba"; //换成要连接的数据库信息 |
| | | 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 (); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 连接mysql数据库 修改 |
| | | * @param sql |
| | | */ |
| | | public static void update(String sql) { |
| | | try { |
| | | int ColumnCount; |
| | | //int RowCount; |
| | | String driver = "com.mysql.jdbc.Driver"; |
| | | String url = "jdbc:mysql://223.82.109.183:2083/zhba"; //换成要连接的数据库信息 |
| | | 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 (); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 连接mysql数据库 删除 |
| | | * @param sql |
| | | */ |
| | | public static void delete(String sql) { |
| | | try { |
| | | int ColumnCount; |
| | | //int RowCount; |
| | | String driver = "com.mysql.jdbc.Driver"; |
| | | String url = "jdbc:mysql://223.82.109.183:2083/zhba"; //换成要连接的数据库信息 |
| | | 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 (); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除本地文件 |
| | | */ |
| | | public static void delete(){ |
| | | File file = new File("D:\\anbao\\sql.json"); |
| | | if (file.isFile() && file.exists()) { |
| | | file.delete(); |
| | | } |
| | | } |
| | | } |