DB2

DB2 is IBM's offering to the highend database market. The latest version of DB2 (Universal Database) is ideal for OLTP, Data Warehousing, Decision Support and everything in between. It's well priced, extremely scalable and runs on virtually every platform out there from handhelds to mainframes.

Loading huge data Files using DB2 loader from java


Hi All,
I am new to DB2 Data base. I am using DB2 8.2 Version. I want to load huge data files using DB2 loader from java. Can I call the Load command from the java.
Like
Runtime.getRuntime.execute("Load Command");
User/Admin uploads large file from the browser. The file is fixed length formate file with .txt extension.
Can any boyd please help me, how and what is the command i need to use? It will be helpful if you give me the sample code for it.
Is it possible calling the DB2 loader from java.
Alternate is, calling the DB2 loader from store procedure. Which is the better idea.
Even i dont know what is the command need to give and its parameters.
Can Anybody please help me? I really appreciate for your help.
Thanks in advance,
Sriha
To use LOAD from a SP, you would have to write the SP in a language like C++. To do it from Java, it would look like this:
// This is code to connect to DB, then a loop to do successive loads, then disconnect
// do import work
System.out.println("Connect");
runTime = Runtime.getRuntime();
db2Command = new StringBuffer("DB2 CONNECT TO ");
db2Command.append(getDbName());
db2Command.append(" USER ");
db2Command.append(dbLogin.getLoggedInUsername());
db2Command.append(" USING ");
db2Command.append(dbLogin.getLoggedInPassword());
child = runTime.exec(db2Command.toString());
inStream = new java.io.InputStreamReader(child.getInputStream());
buffReader = new java.io.BufferedReader(inStream);
inLine = null;
while ((inLine = buffReader.readLine()) != null) {
System.out.println(inLine);
}
exitVal = child.waitFor();
// import data
tigerPath = new File(dataDirectory);
for (i=0; i< rts.length; ++i)
{
importRT(tigerPath,rts[i],cl[i],nl[i],col[i]);
}
System.out.println("Disconnect");
runTime = Runtime.getRuntime();
child = runTime.exec("DB2 DISCONNECT ALL");
inStream = new java.io.InputStreamReader(child.getInputStream());
buffReader = new java.io.BufferedReader(inStream);
inLine = null;
while ((inLine = buffReader.readLine()) != null) {
System.out.println(inLine);
}
exitVal = child.waitFor();
// this is the function to load
public static void importRT(File dir, String recordType, String columnLocations, String nullIndicators, String columns){
int i;
StringBuffer importCommand;
java.io.InputStreamReader inStream;
java.io.BufferedReader buffReader;
String inLine;
int exitVal;
String retString;
try {
final String fileType = new String("." + recordType);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toUpperCase().endsWith(fileType);
}
};
plString = new String(recordType);
String files[] = dir.list(filter);
progMax = files.length;
progCurrent = 0;
display.asyncExec(importTiger);
for (i=0; i< files.length; ++i)
{
importCommand = new StringBuffer("DB2 LOAD CLIENT FROM ");
importCommand.append(dir.getPath());
importCommand.append("\\");
importCommand.append(files[i]);
importCommand.append(" OF ASC METHOD L ");
importCommand.append(columnLocations);
importCommand.append(" NULL INDICATORS ");
importCommand.append(nullIndicators);
importCommand.append(" MESSAGES ");
importCommand.append(dir.getPath());
importCommand.append("\\");
importCommand.append(files[i]);
importCommand.append(".ldm INSERT INTO ANDY.TIGER_");
importCommand.append(recordType);
importCommand.append(" ");
importCommand.append(columns);
importCommand.append(" nonrecoverable without prompting ");
System.out.println(importCommand.toString());
//cStmt.setString(1,importCommand.toString());
//cStmt.execute();
//rs = cStmt.getResultSet();
// get node for database name
child = runTime.exec(importCommand.toString());
inStream = new java.io.InputStreamReader(child.getInputStream());
buffReader = new java.io.BufferedReader(inStream);
inLine = null;
while ((inLine = buffReader.readLine()) != null) {
System.out.print(inLine+"\n");
}
exitVal = child.waitFor();
progCurrent = i+1;
display.asyncExec(importTiger);
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
HTH
Andy

Related Links

To timeout db connection, what can I do?
COBOL program on OS390 can access a SQL2000 database?
Error using || or CONCAT in DB2 SQL procedure
Using Autonomus transactions in DB2
What is FOR FETCH ONLY parameter
Error Building DB2 SQL Procedure
formula for calculating tablespace growth
Error Building DB2 SQL Procedure
DB2 Command Centre
One or more values in the INSERT statement, UPDATE statement, or foreign key update c
The cursor specified in a FETCH or CLOSE statement is not open
test
db2 security
online incremental backups in DB2
DB2 stored procedures filesystem full errors
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] CLI0125E Function sequence error. SQ

Categories

DataBase Dev
MongoDB
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
Crystal Reports
Delphi, C etc
JAVA
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
Brilliant Database
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
New Members & Introduc...
Applications & Tools
Database Concepts & De...
Chit Chat
Marketplace
Job Opportunities
Suggestions & Feedback

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App