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;
|
|
import static org.springblade.common.config.FtpConfig.localPath;
|
import static org.springblade.common.config.FtpConfig.sqlConnect;
|
|
|
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 = 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 ();
|
}
|
}
|
|
/**
|
* 连接mysql数据库 修改
|
* @param sql
|
*/
|
public static void update(String sql) {
|
try {
|
int ColumnCount;
|
//int RowCount;
|
String driver = "com.mysql.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 ();
|
}
|
}
|
|
/**
|
* 连接mysql数据库 删除
|
* @param sql
|
*/
|
public static void delete(String sql) {
|
try {
|
int ColumnCount;
|
//int RowCount;
|
String driver = "com.mysql.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 ();
|
}
|
}
|
|
// /**
|
// * 删除本地文件
|
// */
|
// public static void deletes(String fileName){
|
// File file = new File("D:\\"+fileName);
|
// if (file.isFile() && file.exists()) {
|
// file.delete();
|
// }
|
// }
|
public static void deletess(String fileName){
|
File file = new File(localPath+fileName);
|
if (file.isFile() && file.exists()) {
|
file.delete();
|
}
|
}
|
}
|