I want to convert the records in the JDBC resultset
into insert queries
for some purposes.
Is it possible? If it is pls suggest me the solution.
I want to convert the records in the JDBC resultset
into insert queries
for some purposes.
Is it possible? If it is pls suggest me the solution.
Here is a question about generating CREATE TABLE query from ResultSet. How to create table based on JDBC Result Set
With some changes you should be able to adapt it for an INSERT query also.
Note that, the values have to be added with quotes or with date conversion function etc. as per the data type of the column.
Also, large objects such as CLOB would require some additional bit of work to make them work.
Based on my understanding on your quesstion, You can try like this
try{
ps=con.prepareStatement("select * from login");
rs=ps.executeQuery();
while(rs.next())
{
ps=con.prepareStatement("insert into table2(uname,pswd) values(?,?)");
ps.setString(1,rs.getString(2));// 2-column number
ps.setString(2,rs.getString(3));//3-column number
ps.executeUpdate();
}
}catch(Exception e)
{
System.out.println(e);
}