Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert inside PreparedStatement in java program

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,I do Preparedstatement in java program before i do insert to the table (tranfering from Excell file from PC to DB2 file on AS/400) when i pass parameters first time and execute Preparedstatement it works fine,but when i tryied do it second or whatever time i get an error message
"[SQL7008] File in Library not valid for operation"
Why, i don't understand if you did it once why you cann't do it twice in the loop?
Here my source :


import java.math.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
//import com.ibm.db2.jdbc.app.*;
import com.ibm.as400.access.AS400JDBCDriver.*;


public class MoveExcelToAs400
{


public MoveExcelToAs400()
{
}
public void setValuesAt(javax.swing.JTable ExcelToAs400, java.awt.Frame parent) throws Exception
{

TableModel tableModel;
BigDecimal valueAtTable = null;
Object [][] rowData = new Object[100000][5];
int i = 0 ;
int j = 0;
BigDecimal company = new BigDecimal(87001);
BigDecimal updt = new BigDecimal(20011125);
BigDecimal uptm = new BigDecimal(1000);
BigDecimal fromwater = new BigDecimal(001);
String user = new String("JV");

Connection c = null;
// prepared string to insert into AS400 data file MC034P that
// include : MSCPNY,MSMSLL,MSMTKN,MSMQTY,MSMHAN,MSMHNM,MSMMHL,MSUPID,MSUPDT,MSUPTM

String insertSQL = "Insert INTO NVTHSV.MC034P VALUES(?,?,?,?,?,?,?,?,?,?)";
System.out.println("before try");

try
{
System.out.println("before driver loading");
// Load the AS/400 Toolbox for Java JDBC driver.
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
System.out.println("before driver loading2");
// Get a connection to the database. Since we do not
// provide a user id or password, a prompt will appear.
c = DriverManager.getConnection ("jdbc:as400://AS400M","USERJAVA","USERJAVA");
System.out.println("before driver loading3");

// Get ready to prepared Statement
PreparedStatement pstmt = c.prepareStatement(insertSQL);
System.out.println("prepare prepared statement");

tableModel = ExcelToAs400.getModel();
System.out.println("got the tableModel");
valueAtTable=(BigDecimal)tableModel.getValueAt(j,i);
System.out.println("got the first valueAtTable");


while(valueAtTable != null){
for(i=0; i<=4; i++){
valueAtTable=(BigDecimal)tableModel.getValueAt(j,i);
if(valueAtTable == null) break;

//set path
System.out.println(&quot;1= &quot;+ valueAtTable);
if(i==0) pstmt.setBigDecimal(2,valueAtTable);
//set quantaty of devices
if(i==1) pstmt.setBigDecimal(3,valueAtTable);
//set quantaty of water
if(i==2) pstmt.setBigDecimal(4,valueAtTable);
//set discount on service
if(i==3) pstmt.setBigDecimal(5,valueAtTable);
//set discount on water
if(i==4) pstmt.setBigDecimal(6,valueAtTable);

//rowData[j]= valueAtTable;
System.out.println(&quot;i= &quot; +i + &quot;j= &quot; +j + &quot;valueAtTable= &quot;+valueAtTable);
}

//set company
pstmt.setBigDecimal(1,company);
//set from quantaty of water
pstmt.setBigDecimal(7,fromwater);
//set date
pstmt.setString(8,user);
//set time
pstmt.setBigDecimal(10,uptm);
//set user
pstmt.setBigDecimal(9,updt);
here the problem --------------------->>>>>>>> in
second time:
pstmt.executeUpdate();
j++;

}
} //endtry
catch(Exception e)
{
System.out.println(&quot;I'm at the Exception of moveExcel&quot;);
System.out.println(&quot;1= &quot;+valueAtTable);
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(
parent, e.getMessage(),
&quot;Error&quot;,
JOptionPane.ERROR_MESSAGE);
} //endcatch

}
}


Any suggestion would be appreciate.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top