我是 java 新手,我正在尝试将 old_db 中的数据插入 new_db。我已经尝试过一个程序来做到这一点,它显示了一个错误,比如“语法错误”找不到什么错误。
该程序必须连接到 2 个 postgres db 并选择表中的数据并将它们插入到另一个数据库表中。两个表都有相同的字段和数据类型。
import java.sql.* ;   
public class con2 
{ 
public static void main( String[] args ) 
{ 
try 
{ 
   Connection con = DriverManager.getConnection( "jdbc:postgresql://localhost:5432/old_db","postgres","password");
try
{
   Connection con1 = DriverManager.getConnection( "jdbc:postgresql://localhost:5432/new_db","postgres","password");
 Statement st = con.createStatement();
 Statement st1 = con1.createStatement();   
ResultSet rs = st.executeQuery("SELECT * FROM users"); 
  int val = st1.executeUpdate("insert into users("+"'rs()'"+")");
        rs.close();
                        st.close(); 
                    st1.close(); 
}
catch(SQLException e) 
  { 
         System.out.println( "could not get JDBC connection for new_db: " + e ); 
  } 
}
catch(SQLException e) 
  { 
         System.out.println( "could not get JDBC connection for  old_db: " + e ); 
  } 
} 
} 
我正在使用 jdbc4