Solved

How to automate SQL drop table command?

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Way to decrease size of apk file 9 104
jdbc error in jsp application 20 71
expectj telnet failing 5 49
Why is enum singleton a better approach than static factory 3 47
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

685 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