导库,从一个库中导入另一个库 操作库中的某个表格的内容

public void test(){

Class.forName("com.mysql.jdbc.Driver");

String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
String user = "root";
String password = "testaaa";
Connection conn = (Connection) DriverManager.getConnection(url, user, password);
// Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/itbuy_resource?user=root&password=testaa");
Statement stmt = conn.createStatement(); 
ResultSet rs = stmt.executeQuery("select * from  tablename");
StringBuffer sb = new StringBuffer();
int i = 0;
if(tableName.equals("by_resource_user")){
while (rs.next()) {
i++;
sb.append("INSERT INTO test  (ID,CREATETIME,STATUS) values(");

sb.append("'");
sb.append(rs.getString("accountname"));
sb.append("'");
sb.append(",");

sb.append("'");
sb.append(rs.getString("createtime"));
sb.append("'");
sb.append(",");
  
sb.append("\r\n");
sb.append("\r\n");

byte[] b = new byte[]{};
b = sb.toString().getBytes();
FileOutputStream out ;
try {
out = new FileOutputStream("D://"+tableName+".sql");
out.write(b, 0, b.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

你可能感兴趣的:(导库,从一个库中导入另一个库 操作库中的某个表格的内容)