package com.zpms.portal.management.order;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MysqlDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//驱动程序名
String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名scutcs
String url = "jdbc:mysql://yplproddb1.mysql.rds.aliyuncs.com:3308/zmdj";
// MySQL配置时的用户名
String user = "ypl";
// Java连接MySQL配置时的密码
String password = "TFcPVWli7K";
// 加载驱动程序
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
// statement用来执行SQL语句
PreparedStatement statement1 = null;
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sqlList = "select key_value,coach_type from ypl_search_keyword where sex = 0 ";
String sqlinsert = "insert into ypl_search_keyword (key_value,coach_type,sex) values (?,?,?)";
ResultSet rs = statement.executeQuery(sqlList);
while (rs.next()) {
statement1 = conn.prepareStatement(sqlinsert);
statement1.setString(1,"女" + rs.getString("key_value"));
statement1.setInt(2, rs.getInt("coach_type"));
statement1.setInt(3, 2);
statement1.addBatch();
statement1.executeBatch();
}
statement1.close();
conn.close();
rs.close();
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class MysqlDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//驱动程序名
String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名scutcs
String url = "jdbc:mysql://yplproddb1.mysql.rds.aliyuncs.com:3308/zmdj";
// MySQL配置时的用户名
String user = "ypl";
// Java连接MySQL配置时的密码
String password = "TFcPVWli7K";
// 加载驱动程序
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("Succeeded connecting to the Database!");
// statement用来执行SQL语句
PreparedStatement statement1 = null;
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sqlList = "select key_value,coach_type from ypl_search_keyword where sex = 0 ";
String sqlinsert = "insert into ypl_search_keyword (key_value,coach_type,sex) values (?,?,?)";
ResultSet rs = statement.executeQuery(sqlList);
while (rs.next()) {
statement1 = conn.prepareStatement(sqlinsert);
statement1.setString(1,"女" + rs.getString("key_value"));
statement1.setInt(2, rs.getInt("coach_type"));
statement1.setInt(3, 2);
statement1.addBatch();
statement1.executeBatch();
}
statement1.close();
conn.close();
rs.close();
}
}