Program runs fine but do not insert into table column
I have written a program to get 2 columns "ID","XML" from one table say "PROCESS_OLD" of type varchar and image and copy them to 2 columns "ID","XML" of type varchar and nText of another table "ProcessTest"
My program reads from "PROCESS_OLD" fine and also the code of writting to 2nd table "ProcessTest "throws no exception
when I try to print the inserted columns I can print them fine.But when I look at Table only one column "ID" gets inserted and not XML
I am also converting column XML from TableA of type image to Sting in between
Here is the code
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.*;
publicclass Image2nText
{
Connection con;
Statement stmt;
ResultSet rs;
ResultSet rs2;
public Image2nText()
{
/*
Register the diver and get the connection con
*/
stmt = con.createStatement();
Statement stmt2 = con.createStatement();
rs = stmt.executeQuery("select XML,ID from PROCESS_OLD");
while (rs.next())
{
//convert image to String
StringBuffer sb =new StringBuffer();
InputStream is = rs.getBinaryStream("XML");
DataInputStream din =new DataInputStream(is);
String line =null;
while ((line = din.readLine()) !=null)
{
sb.append(line +"\n");
}
String currentRow = sb.toString();
System.out.println(currentRow);
String ID=rs.getString("ID");
PreparedStatement ps = con.prepareStatement("insert intoProcessTest (XML,ID) values (?,?)");
ps.setString(1, currentRow);
ps.setString(2, ID);
ps.executeUpdate();
ps.close();
is.close();
rs2 = stmt2.executeQuery("select XML,ID from ProcessTest");
while (rs2.next())
{
System.out.println(rs2.getString("XML"));//prints out compeletely fine
System.out.println(rs2.getString("ID"));
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
rs2.close();
rs.close();
stmt.close();
con.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* @param args
*/
publicstaticvoid main(String[] args)
{
Image2nText x =new Image2nText();
}
}

