Solved

How to automate SQL drop table command?

Posted on 2004-09-07
2
390 Views
Last Modified: 2008-01-09
Hello Everybody,

I'm using JDBC connection to drop the table. But it is giving me following error.
I have tested my code for " Select * from EMP " command on remote/local machines and it worked. Now why isn't  " drop table EMP " wouldn't work?  Is there any other way I can automate "drop table" functionality? I'm using IBM UDB. I wanted to use Command Line Processor (CLP) but the problem is all the commands should run in CLP. So I can say:

<    db2cmd db2 connect to sample  > but then it opens another window having db2 environment and now I would  direct my second command < db2 drop table emp  >



COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0637E  QUERY cannot be found.
      at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throwInvalidQueryError(Unknown Source)
      at COM.ibm.db2.jdbc.app.DB2Statement.executeQuery(Unknown Source)
      at com.ibm.db2tools.common.DB2QueryDatabase.db2QueryDatabase(DB2QueryDatabase.java:42)
      at tasks.QueryDB2.dropTable(QueryDB2.java:66)
      at tasks.QueryDB2.testMain(QueryDB2.java:88)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.rational.test.ft.sys.FtReflection.invokeMethod2Ext(Unknown Source)
      at com.rational.test.ft.sys.FtReflection.invokeMethodExt(Unknown Source)
      at com.rational.test.ft.sys.FtReflection.invokeMethodExt(Unknown Source)
      at com.rational.test.ft.script.RationalTestScript.runMain(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.rational.test.ft.sys.FtReflection.invokeMethod2Ext(Unknown Source)
      at com.rational.test.ft.sys.FtReflection.invokeMethodExt(Unknown Source)
      at com.rational.test.ft.sys.FtReflection.invokeMethodExt(Unknown Source)
      at com.rational.test.ft.application.ScriptPlayback.runScript(Unknown Source)
      at com.rational.test.ft.application.ScriptPlayback.run(Unknown Source)
      at com.rational.test.ft.rational_ft.run(Unknown Source)
      at com.rational.test.ft.rational_ft.main(Unknown Source)
java.lang.NullPointerException


Thanks,
Paluindian
0
Comment
Question by:paluindian
2 Comments
 
LVL 6

Accepted Solution

by:
dorothy2 earned 50 total points
ID: 12000215
I'm not familiar with the DB2 classes, but I did take a look at the API for java.sql. Executing a query implies that you are going to get a ResultSet return value. That's obviously not what you want with a Drop Table command.

Look in the API documentation and see if there is a method call execute which takes a String parameter. You should be able to drop and create tables through JDBC using that method.

Here is the URL for the JDBC APIs:

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/package-summary.html

Good luck,

Dorothy
0
 

Author Comment

by:paluindian
ID: 12001082
Hi Dorothy,

Yes, you were correct. I was using :

Resultset rs = stmt.executeQuery(strQuery);

till now which was not correct. I searched and found out that I should use the follwoing :

stmt.executeUpdate(" drop table emp");

Now it is working,
Thanks for pointing out mistake,

Paluindian
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now