1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
package P1;
import java.sql.*;
public class hhh {
public static void main(String[] args) throws SQLException {
Connection conn = null;
Connection conn2 = null;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection("jdbc:oracle:thin:@server:1521:db1","user","pass");
conn2 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:db2","user","pass");
Statement instruction = conn.createStatement();
Statement instruction0 = conn.createStatement();
ResultSet resultat = instruction.executeQuery("SELECT id,nom,prenom,email,id_authentification FROM table1");
PreparedStatement stat1 = conn2.prepareStatement("insert into table2(id,nom,prenom,email,login,password) values(?,?,?,?,?,?)");
while(resultat.next())
{
ResultSet resultat2 =instruction0.executeQuery("SELECT login,passworde FROM authentification where id_authentification="+resultat.getInt("id_authentification"));
try{
while(resultat2.next())
{
try{
stat1.setInt(1,resultat.getInt("id"));
stat1.setString(2,resultat.getString("nom"));
stat1.setString(3,resultat.getString("prenom"));
stat1.setString(4,resultat.getString("email"));
stat1.setString(5,resultat2.getString("login"));
stat1.setString(6,resultat2.getString("passworde"));
stat1.executeUpdate();
}catch(Exception e1){
e1.printStackTrace();
}
}
}catch(Exception e2){
e2.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager