Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sync.dev;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Locale;
- import mysql.MysqlConn;
- import ora.OraConnect;
- public class Main {
- public static void getIns() throws SQLException, ClassNotFoundException {
- int id = 0;
- String fio = null;
- String nam = null;
- String otch = null;
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Locale.setDefault(Locale.ENGLISH);
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "KOLTERNEW", "1111");
- Statement stmt = conn.createStatement();
- String q1 = "select * from sotr_change where ctyp = 'i' ";
- ResultSet rs = stmt.executeQuery(q1);
- rs.next();
- while (!rs.isAfterLast()) {
- id = rs.getInt(1);
- fio = rs.getString(2);
- nam = rs.getString(3);
- otch = rs.getString(4);
- rs.next();
- }
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn2 = DriverManager.getConnection("jdbc:mysql://localhost:3306/library", "kolter", "1111");
- Statement stmt2 = conn2.createStatement();
- for (int i = 0; i < rs.getFetchSize(); i++) {
- String q2 = "INSERT INTO sotr (kod_sotr, fam, im, ot) VALUES ('" + id + "', '" + fio + "','" + nam + "','" + otch + "')";
- stmt2.executeUpdate(q2);
- }
- conn.commit();
- conn.close();
- conn2.commit();
- conn2.close();
- }
- public static void getUpd() throws SQLException, ClassNotFoundException {
- int id = 0;
- String fio = null;
- String nam = null;
- String otch = null;
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Locale.setDefault(Locale.ENGLISH);
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "KOLTERNEW", "1111");
- Statement stmt = conn.createStatement();
- String q1 = "select * from sotr_change where ctyp = 'U' ";
- ResultSet rs = stmt.executeQuery(q1);
- rs.next();
- while (!rs.isAfterLast()) {
- id = rs.getInt(1);
- fio = rs.getString(2);
- nam = rs.getString(3);
- otch = rs.getString(4);
- rs.next();
- }
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn2 = DriverManager.getConnection("jdbc:mysql://localhost:3306/library", "kolter", "1111");
- Statement stmt2 = conn2.createStatement();
- for (int i = 0; i < rs.getFetchSize(); i++) {
- String q2 = "UPDATE sotr SET fam = '" + fio + "', im = '"+ nam +"', ot = '"+ otch +"' WHERE kod_sotr = '"+ id +"'";
- stmt2.executeUpdate(q2);
- }
- conn.commit();
- conn.close();
- conn2.commit();
- conn2.close();
- }
- public static void getUvolenMY() throws ClassNotFoundException, SQLException {
- int iduvolmy = 0;
- Class.forName("com.mysql.jdbc.Driver");
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/library", "kolter", "1111");
- Statement stmt = conn.createStatement();
- String q1 = "SELECT * FROM uvolmy";
- ResultSet rs = stmt.executeQuery(q1);
- rs.next();
- while (!rs.isAfterLast()) {
- iduvolmy = rs.getInt(1);
- rs.next();
- }
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Locale.setDefault(Locale.ENGLISH);
- Connection conn2 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "KOLTERNEW", "1111");
- Statement stmt2 = conn2.createStatement();
- String q2 = "TRUNCATE TABLE uvolenor";
- stmt2.executeQuery(q2);
- for (int i = 0; i < rs.getFetchSize(); i++) {
- String q3 = "INSERT INTO uvolenor (kod_sotr) VALUES ('" + iduvolmy + "')";
- stmt2.executeQuery(q3);
- conn2.commit();
- }
- conn.commit();
- conn.close();
- conn2.commit();
- conn2.close();
- }
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- /*System.out.println("Sync with mysql..");
- getIns();
- getUpd();
- System.out.println("Mysql sync done");
- System.out.println("--------------");*/
- System.out.println("Sync with ora..");
- getUvolenMY();
- System.out.println("Ora sync done");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement