Hi,
I am trying to declare and cursor and thn load from that cursor into
another table. Since I have almost 4 million records, I cant do it
without the cursor which reduces the time by almost 1/10th.
I tried to create a sql statement for "load from cursor cur insert into
table name" using java stored procedure, but this isnt recognised by
sql since load isnt a sql keyword. So whats the solution to this. I
have to do it programatically rahter than going to db2clp everytime I
want to load data.
Any suggestions are welcome..
This is the excerpt of the code I am trying to build
try
{
String sql="declare cur cursor for SELECT * from tablename;
PreparedStatement st= con.prepareStatement(sql);
st.execute(sql); // tried regular Statement class also
}
catch (SQLException e)
{
System.out.println("Error in declaring the cursor");
e.printStackTrace();
}
try
{
String sql2 = "load from cur of cursor insert into schema.customer
nonrecoverable";
Statement st1=con.createStatement();
st1.execute(sql2);
}
catch (SQLException e1)
{
System.out.println("Error loading form the cursor");
}
Throws exception at both the places. The log looks like this:
SELECT * from tablename
Error in declaring the cursor
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/6000] SQL0104N An
unexpected token "load from cur of cursor" was found following
"BEGIN-OF-STATEMENT". Expected tokens may include: "<space>".
SQLSTATE=42601
at
COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(SQLExceptionGenerator.java(Compiled
Code))
at
COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_S QLException(SQLExceptionGenerator.java:217)
at
COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_r eturn_code(SQLExceptionGenerator.java:449)
at
COM.ibm.db2.jdbc.app.DB2Statement.execute2(DB2Stat ement.java:857)
at
COM.ibm.db2.jdbc.app.DB2Statement.execute(DB2State ment.java:530)
at
PKG60301124637844.InitControl.initCustomer(InitCon trol.java:344)
at
PKG60301124637844.InitControl.initControl(InitCont rol.java:49)