Solved

How to automate SQL drop table command?

Posted on 2004-09-07
2
400 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 135
mysql jsp example issue 32 96
swing controls 2 37
American Express @Work site and Java 4 97
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

738 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