Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to automate SQL drop table command?

Posted on 2004-09-07
2
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
dorothy2 earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

730 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