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();

}

}

[4393 byte] By [ushradhaa] at [2007-11-26 19:12:59]
# 1
So when you read and dump the table using JDBC, all the data is correct? But when you "look at" the table you don't see the XML column?Maybe you should get new glasses. Or did "look at" mean something other than "look at"?
DrClapa at 2007-7-9 21:12:05 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Did you try adding line to commit to DB.con.commit();
masuda1967a at 2007-7-9 21:12:05 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Thank you masuda1967.I tried con.commit but it made no difference
ushradhaa at 2007-7-9 21:12:05 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

If you are using oracle, you can try inserting with select, but I do not know your database support this. If it does, this may be faster and safer than extracting into stream and inserting back to database.

PreparedStatement ps = con.prepareStatement("INSERT INTO ProcessTest (XML,ID) SELECT XML, ID FROM PROCESS_OLD" );

ps.executeUpdate();

masuda1967a at 2007-7-9 21:12:05 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...