Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Need help in batch insert using jdbc

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Team,
package com.cc.apps.vv.main;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import com.healthmarketscience.jackcess.Column;
import com.healthmarketscience.jackcess.Cursor;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.Table;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.xx.apps.yy.model.Login;
import java.sql.*;
public class Test {

public static void main(String args[]) throws IOException, SQLException{
Table table = null;
Database db = null;
Login login = null;
ArrayList<Login> rowList = null;
Connection con = null;
Statement st = null;
try {
rowList = new ArrayList();

db = Database.open(new File("C:\\Users\\tt\\Accdb.mdb"));

table = db.getTable("Access");

for(Map<String, Object> row : table) {
login = new Login();
if(row.get("P_ID")!=null){
login.setPId(row.get("P_ID").toString());
}
if(row.get("R_ID")!=null){
login.setRId(row.get("R_ID").toString());
}if(row.get("LNumber")!=null){
login.setLocNum(row.get("LNumber").toString());
}
rowList.add(login);
}

login.setRowList(rowList);
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
con = DriverManager.getConnection(
"jdbc:as400://system-name/default-schema", "aa",
"bb");

con.setAutoCommit(false);
st = con.createStatement();
String insertTableSQL = "INSERT INTO Master (P_ID,R_ID,LNumber) VALUES (?,?,?)";
PreparedStatement preparedStatement = con.prepareStatement(insertTableSQL);
preparedStatement = con.prepareStatement(insertTableSQL);
for(Login login1 : rowList)
{
preparedStatement.setString(1, login1.getPId());
preparedStatement.setString(2, login1.getRId());
preparedStatement.setString(3, login1.getLocNum());
preparedStatement.addBatch();
preparedStatement.executeBatch();
}


con.commit();
} catch (ClassNotFoundException e) {
try {
con.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
}
The above code will do

1. Read the rows from the access table using jackcess
2.And add the row object to the list.
3Then I have connect the As400 database and batch insert the list values in Master table.

when i run this program am getting following error

Exception in thread "main" java.sql.SQLException: [PWS0082] library(s) not added to the library list.
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:703)
at com.ibm.as400.access.AS400JDBCConnection.setServerAttributes(AS400JDBCConnection.java:4122)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3346)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3216)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3209)
at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1411)
at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:1248)
at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:389)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)

I need to do sample batch insert in as400 table.
Please help what mistake am doing .

Thanks in Advance





 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@"charu java"
Like I had requested earlier you really need to check your Purple Mooseages and take appropriate action. Please note this is not optional.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic