하나의 mysql 데이터베이스에서 다른 데이터베이스로 데이터를 전송하려고합니다. 하나의 연결 이름은 db 이름, 사용자 이름 및 pwd입니다 (이 위치는 원격 위치에 있어야 함) . 그리고 다른 데이터 소스를 사용하고 있습니다.하나의 MySQL 데이터베이스에서 다른 데이터베이스로 삽입
public class errorlog {
public static void main(String[] args)
{
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded mysql1server");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded mysql");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("not loaded");
}
String connectionUrl = "jdbc:mysql//localhost:3306/db1" ;
String connectionUrl2="jdbc:odbc:test";
Connection con=null;
Connection con2=null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
con = DriverManager.getConnection(connectionUrl,"root","root");
System.out.println("CONNECTED1 mysql1");
con2 = DriverManager.getConnection(connectionUrl2);
System.out.println("CONNECTED2 mysql");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
stmt = con.createStatement();
rs=stmt.executeQuery("select * FROM db1.db1_table");
System.out.print("Select executed");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while (rs.next()) {
int col1 = rs.getInt("col1");
String col2=rs.getString("col2");
Date TimeStamp = rs.getDate("Time Stamp");
String insertSql ="Insert into db2.db2_table (`col1`,`col2`) values(?,?)";
pstmt = con2.prepareStatement(insertSql);
pstmt.setInt(1,col1);
pstmt.setString(2,col2);
pstmt.setDate(3,(java.sql.Date) TimeStamp);
pstmt.executeUpdate();
pstmt.close();
System.out.println("insert done");
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("out insert done");
}
}
내가 같은 오류가 점점 오전 "MySQL은 // 로컬 호스트 : 없음 JDBC에 대한 발견에 적절한 드라이버, 사용자 = 루트; 3306/여기서 databaseName = DB1을 비밀 번호 = 루트"
을 알려 주시기 바랍니다 어디에서 틀렸다.
또한 요구 사항 -
나는 시간 값을 보유 할 데이터로 업데이트 계속하는 구성 파일을 사용하려면이 가져온 .Ex- 파일이 값 2014년 3월 18일 12시 0분 0초을 보유하고있다 , 프로그램은 1 시간의 정기적 인 간격으로 실행됩니다. 파일을 보유한 후에 만 데이터를 가져 오려고합니다. 그리고 한 번 파일을 업데이트해야합니다.
내가 어떻게 할 수 있는지 알려 주시기 바랍니다.
은 제안에 따라 변경되었으며 병은 이미 추가되었습니다. 같은 오류가 있습니다. 코드를 위의 코드로 편집하십시오. – master
연결 URL에 사용자 이름과 암호가 있음을 알게되었습니다. 그것들을 꺼내고 DriverManager.getConnection (connectionURL, "root", "root")을 사용하십시오. – captainroxors
여전히 같은 오류 .. 편집 된 코드 pls를보십시오. 두 개의 드라이버가로드 된 명령문이 인쇄됩니다. – master