i am new to java, i am trying to insert a data from old_db to new_db.
i have tried a program to do that, its shows a error like “syntax error” cant find what the error.
the program has to getconnection to 2 postgres db and select data in a table and insert them into
another database table. both table have same fields and datatype.
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 );
}
}
}
i am using jdbc4
I have written a program like shown below, it’s working.
Thanks for the suggestions.