كيف اسويله thread ينقل على الجدول الثاني بعد اسبوع
package org.Kodejava.example.sql;
import java.sql.*;
public class MSAccessConnect3 {
public static void main(String[] args) {
MSAccessConnect3 mSAccessConnect3 = new MSAccessConnect3();
// mSAccessConnect3.insert();
mSAccessConnect3.selectAndInsert();
}
void insert() {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:database3");
Statement sta = con.createStatement();
// insert 3 rows
int count = 0;
int c = sta.executeUpdate("INSERT INTO MESSAGE_OUT"
+ "(MESSAGE_ID,JOB_ID,SMS_SENDER)"
+ "VALUES (1,'11','Hiiii')");
count = count + c;
c = sta.executeUpdate("INSERT INTO MESSAGE_OUT"
+ "(MESSAGE_ID,JOB_ID,SMS_SENDER)"
+ "VALUES (2,'22','see you')");
count = count + c;
c = sta.executeUpdate("INSERT INTO MESSAGE_OUT"
+ "(MESSAGE_ID,JOB_ID,SMS_SENDER)"
+ "VALUES (3,'33','welcome')");
count = count + c;
System.out.println("Number of rows inserted:" + count);
sta.close();
con.close();
} catch (Exception e) {
System.err.println("Exception:" + e.getMessage());
}
}
/**
*
*/
void selectAndInsert() {
Connection con = null;
Statement selectSta = null;
Statement insertSta = null;
ResultSet rs = null;
int messageId;
int jobId;
String smsSender;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:database3");
selectSta = con.createStatement();
rs = selectSta.executeQuery("select*from MESSAGE_OUT");
if (rs == null) {
System.out.println("no data found");
return;
} else
System.out.println("connection established...");
System.out.println("after select sta");
while (rs.next()) {
messageId = rs.getInt("MESSAGE_ID");
jobId = rs.getInt("JOB_ID");
smsSender = rs.getString("SMS_SENDER");
System.out.println("MESSAGE_ID==" + messageId);
System.out.println("JOB_ID==" + jobId);
System.out.println("SMS_SENDER==" + smsSender);
// System.out.println("insert into MESSAGE_OUT2 values ("+
// MESSAGE_ID+","+JOB_ID+",'"+SMS_SENDER+"')") ;
insertSta = con.createStatement();
insertSta.execute("insert into MESSAGE_OUT2 values ("
+ messageId + "," + jobId + ",'" + smsSender + "')");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try {
insertSta.close();
selectSta.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}