小弟我将两个表里面的数据分别写进了两个数组,在对数组进行比较,找出它们之间的不同数据,那么小弟我该写一个什么方法可以将找出来的这些不一样的数据写进另外一张表里面
我将两个表里面的数据分别写进了两个数组,在对数组进行比较,找出它们之间的不同数据,那么我该写一个什么方法可以将找出来的这些不一样的数据写进另外一张表里面
我在做两个数据库表的数据对比的时候,我将两个表里面的数据分别写进了两个数组,在对数组进行比较,找出它们之间的不同数据,那么我该写一个什么方法可以将找出来的这些不一样的数据写进另外一张表里面,希望各位大侠能够给出代码!!
public static void main(String args[]) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
HashMap map = new HashMap();
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
String sqla = "select newindex from newtable";
pstmt = conn.prepareStatement(sqla);
rs = pstmt.executeQuery();
String[] b = new String[100];
int i = 0;
while (rs.next()) {
b[i] = rs.getString(1);
i++;
}
//System.out.println("=====================");
for (int j = 0; j < b.length; j++) {
// System.out.println("最新进程:"+a[j]);
}
String sqlb = "select hrSWRunIndex from hrswrun";
pstmt = conn.prepareStatement(sqlb);
rs = pstmt.executeQuery();
String[] a = new String[100];
int m = 0;
while (rs.next()) {
a[m] = rs.getString(1);
m++;
}
//System.out.println("=====================");
for (int j = 0; j < a.length; j++) {
//System.out.println("上一次执行进程"+b[j]);
}
------解决方案--------------------
两个表结构一样?
inset into a select * from b where b.id not in (select id from a);
数据量不大试试这个吧,呵呵 大数据量就死翘翘了.
------解决方案--------------------
用HashSet吧,把两个数组的元素都add到Set(自动过滤相同元素)中,然后把Set保存到数据库表中就可以了
我在做两个数据库表的数据对比的时候,我将两个表里面的数据分别写进了两个数组,在对数组进行比较,找出它们之间的不同数据,那么我该写一个什么方法可以将找出来的这些不一样的数据写进另外一张表里面,希望各位大侠能够给出代码!!
public static void main(String args[]) throws Exception {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
HashMap map = new HashMap();
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
String sqla = "select newindex from newtable";
pstmt = conn.prepareStatement(sqla);
rs = pstmt.executeQuery();
String[] b = new String[100];
int i = 0;
while (rs.next()) {
b[i] = rs.getString(1);
i++;
}
//System.out.println("=====================");
for (int j = 0; j < b.length; j++) {
// System.out.println("最新进程:"+a[j]);
}
String sqlb = "select hrSWRunIndex from hrswrun";
pstmt = conn.prepareStatement(sqlb);
rs = pstmt.executeQuery();
String[] a = new String[100];
int m = 0;
while (rs.next()) {
a[m] = rs.getString(1);
m++;
}
//System.out.println("=====================");
for (int j = 0; j < a.length; j++) {
//System.out.println("上一次执行进程"+b[j]);
}
------解决方案--------------------
两个表结构一样?
inset into a select * from b where b.id not in (select id from a);
数据量不大试试这个吧,呵呵 大数据量就死翘翘了.
------解决方案--------------------
用HashSet吧,把两个数组的元素都add到Set(自动过滤相同元素)中,然后把Set保存到数据库表中就可以了