Solved

How to automate SQL drop table command?

Posted on 2004-09-07
2
386 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

772 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

11 Experts available now in Live!

Get 1:1 Help Now