If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Connector SQL Error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-09, 10:44
pradeepcheers pradeepcheers is offline
Registered User
 
Join Date: Dec 2009
Posts: 4
Connector SQL Error

Hi Everyone,

I'm trying to export a table into a text file and I'm getting connector error at the run time. I have tried with 2 versions of db2jcc.jar connector jars. But getting the following errors. Please help.

C:\JDK5\TryJava>javac ExportDB.java

C:\JDK5\TryJava>java ExportDB
exportCMD = EXPORT TO K:\20091222\orp_TIPDEFGRUPO.txt OF DEL MESSAGES K:\2009122
2\errors.txt SELECT * FROM OR4ADM.ORP_TIPDEFGRUPO
com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, S
QLERRMC: K:\20091222\errors.txt;MESSAGES;ON
at com.ibm.db2.jcc.b.nh.b(nh.java:1376)
at com.ibm.db2.jcc.b.nh.c(nh.java:1363)
at com.ibm.db2.jcc.a.db.k(db.java:352)
at com.ibm.db2.jcc.a.db.e(db.java:96)
at com.ibm.db2.jcc.a.t.e(t.java:83)
at com.ibm.db2.jcc.a.sb.h(sb.java:167)
at com.ibm.db2.jcc.b.nh.p(nh.java:1336)
at com.ibm.db2.jcc.b.oh.d(oh.java:2474)
at com.ibm.db2.jcc.b.ph.W(ph.java:94)
at com.ibm.db2.jcc.b.ph.execute(ph.java:77)
at ExportDB.main(ExportDB.java:52)

CODE:
Connection conn = null;
CallableStatement cstmt = null;
String url = "jdbc:db2://dbxxxxs2.unix.ammmm.co.uk:50000/DUT01";
String driver = "com.ibm.db2.jcc.DB2Driver";
String userName = "durp";
String password = "xxxxx";
try {
Class.forName(driver).newInstance();
System.out.println("Connected to the database2");
conn = DriverManager.getConnection(url,userName,password) ;
System.out.println("Connected to the database3");
cstmt = conn.prepareCall("CALL SYSPROC.ADMIN_CMD (?)");

String exportCMD = "EXPORT TO K:\\20091222\\orp_TIPDEFGRUPO.txt OF DEL MESSAGES K:\\20091222\\errors.txt SELECT * FROM OR4ADM.ORP_TIPDEFGRUPO";
cstmt.setString(1,exportCMD);
System.out.println ("exportCMD = " + exportCMD );
cstmt.execute();

cstmt.close();
conn.close();

} catch (Exception e) {
e.printStackTrace();
}

}

Thanks
Pradeep

Last edited by pradeepcheers; 12-23-09 at 06:13.
Reply With Quote
  #2 (permalink)  
Old 12-22-09, 11:11
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I doubt that the directory K:\20091222 exists on db2bks2.unix.anplc.co.uk.
Reply With Quote
  #3 (permalink)  
Old 12-22-09, 11:56
pradeepcheers pradeepcheers is offline
Registered User
 
Join Date: Dec 2009
Posts: 4
The SQL will work fine with DB2 Control Center. This K:\20091222 is a shared folder where I need to export the table. I tried changing the location to C:\20091222 but still fails with the same error

exportCMD = EXPORT TO C:\20091222\orp_TIPDEFGRUPO.txt OF DEL MESSAGES C:\2009122
2\errors.txt SELECT * FROM OR4ADM.ORP_TIPDEFGRUPO
com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, S
QLERRMC: C:\20091222\errors.txt;MESSAGES;ON
at com.ibm.db2.jcc.b.nh.b(nh.java:1376)
at com.ibm.db2.jcc.b.nh.c(nh.java:1363)
at com.ibm.db2.jcc.a.db.k(db.java:352)
at com.ibm.db2.jcc.a.db.e(db.java:96)
at com.ibm.db2.jcc.a.t.e(t.java:83)
at com.ibm.db2.jcc.a.sb.h(sb.java:167)
at com.ibm.db2.jcc.b.nh.p(nh.java:1336)
at com.ibm.db2.jcc.b.oh.d(oh.java:2474)
at com.ibm.db2.jcc.b.ph.W(ph.java:94)
at com.ibm.db2.jcc.b.ph.execute(ph.java:77)
at ExportDB.main(ExportDB.java:52)

Please help.

Thanks
Pradeep
Reply With Quote
  #4 (permalink)  
Old 12-22-09, 12:31
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
ADMIN_CMD() runs on the server; it has no idea what "C:" or "K:" might be. EXPORT must refer to a server local path, which you would know if you'd read the manual.
Reply With Quote
  #5 (permalink)  
Old 12-22-09, 14:00
pradeepcheers pradeepcheers is offline
Registered User
 
Join Date: Dec 2009
Posts: 4
Thanks for your help.

Is there some other way of exporting tables to the files into local folder?

Thanks
Pradeep
Reply With Quote
  #6 (permalink)  
Old 12-23-09, 05:06
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Run the "EXPORT" utility at the client and don't use the ADMIN_CMD stored procedure.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 12-23-09, 05:38
pradeepcheers pradeepcheers is offline
Registered User
 
Join Date: Dec 2009
Posts: 4
Thanks a lot for the reply.

But I don't understand. Could you please explain this to me.

Can you provide the code please?

Regards
Pradeep
Reply With Quote
  #8 (permalink)  
Old 12-23-09, 06:35
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Unless you want to write the functionality yourself in your Java application, you can install the DB2 client, connect your application through that client to the DB2 server, and then run the EXPORT command that the DB2 client has built-in locally at the client. It's straight-forward and "just" requires the implementation part. (The only critical point is that your Java application must be run with an authorization that allows you to use the DB2 client.)
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #9 (permalink)  
Old 12-28-09, 10:29
cubbatjum cubbatjum is offline
Registered User
 
Join Date: Dec 2009
Posts: 1
if upgrading just the db - it should be no problem
Reply With Quote
  #10 (permalink)  
Old 12-28-09, 10:41
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by cubbatjum View Post
if upgrading just the db - it should be no problem
??? I didn't mention anything about upgrading, and even a newer version of DB2 can't resolve the fundamental issue that code running on the server cannot really write to the file system on the client system.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On