467,202 Members | 1,027 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,202 developers. It's quick & easy.

An error on search table.


Hello,I am a fresh man to study the DB2.An error occured when I try to
Run a Java class.

Details of the Error:

Code:
--------------------

com.ibm.db2.jcc.b.SqlException:DB2 SQL error:SQLCODE:-204,SQLSTATE:42704, SQLERRMC :DB2ADMIN.TEST

--------------------
Following is the source:

Code:
--------------------

/*
* JDB2.java
*
* Created on 2006
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author Administrator
*/
import java.sql.*;
public class JDB2{
//Create the main method
public static void main(String args[]){
//Load JDBC Driver
String Driver="com.ibm.db2.jcc.DB2Driver";
//Create the URL
String Url="jdbc:db2://localhost:50000/BD";
//Use the Class.forName
try{
Class.forName(Driver).newInstance();
}catch (Exception e){
System.out.println(e);
}
//Create Connection
System.out.println("Conneting...");
try{
Connection conn=DriverManager.getConnection(Url,"db2admin","8 30401");

Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from test");
while(rs.next()) {
int ID=rs.getInt("id");
String NAME=rs.getString("name");
System.out.println("ID"+"\t\t"+"NAME");
System.out.println(ID+"\t\t"+NAME);
}
}catch(SQLException sqle){
System.err.println(sqle);
}

}
}
--------------------
--
TurboDisk
------------------------------------------------------------------------
TurboDisk's Profile: http://www.dbtalk.net/m197
View this thread: http://www.dbtalk.net/t300860

Apr 20 '06 #1
  • viewed: 1348
Share:
5 Replies
may be you are refering to the object which does not exist,
check out the table and column name you are useing

Apr 20 '06 #2
In article <11*********************@u72g2000cwu.googlegroups. com>,
SR********@REDIFFMAIL.COM says...
may be you are refering to the object which does not exist,
check out the table and column name you are useing


And also the table prefix. It defaults to the name of the user used in
the connect statement.
Apr 20 '06 #3

Thanks to everybody.But I don't know how to modify it.
--
TurboDisk
------------------------------------------------------------------------
TurboDisk's Profile: http://www.dbtalk.net/m197
View this thread: http://www.dbtalk.net/t300860

Apr 20 '06 #4
Change your SQL statement in the program to:
select count(*) from syscat.tables
or
values(current timestamp)

The second will always return a row while the first verifies that your
connection has read access to the database catalog tables.

Your connect statement includes the userid and password. The full table
name you are accessing is "db2admin.test". If you created the table from
a connection using your own userid, then you need to use your userid and
password in the connect statement or use:
select * from userid.test

I'd suggest reading a good primer book on db2 to learn about the basics.

Phil Sherman

TurboDisk wrote:
Hello,I am a fresh man to study the DB2.An error occured when I try to
Run a Java class.

Details of the Error:

Code:
--------------------

com.ibm.db2.jcc.b.SqlException:DB2 SQL error:SQLCODE:-204,SQLSTATE:42704, SQLERRMC :DB2ADMIN.TEST

--------------------
Following is the source:

Code:
--------------------

/*
* JDB2.java
*
* Created on 2006
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author Administrator
*/
import java.sql.*;
public class JDB2{
//Create the main method
public static void main(String args[]){
//Load JDBC Driver
String Driver="com.ibm.db2.jcc.DB2Driver";
//Create the URL
String Url="jdbc:db2://localhost:50000/BD";
//Use the Class.forName
try{
Class.forName(Driver).newInstance();
}catch (Exception e){
System.out.println(e);
}
//Create Connection
System.out.println("Conneting...");
try{
Connection conn=DriverManager.getConnection(Url,"db2admin","8 30401");

Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from test");
while(rs.next()) {
int ID=rs.getInt("id");
String NAME=rs.getString("name");
System.out.println("ID"+"\t\t"+"NAME");
System.out.println(ID+"\t\t"+NAME);
}
}catch(SQLException sqle){
System.err.println(sqle);
}

}
}
--------------------

Apr 20 '06 #5

Thanks very much Phil.Thanks very much everybody.
--
TurboDisk
------------------------------------------------------------------------
TurboDisk's Profile: http://www.dbtalk.net/m197
View this thread: http://www.dbtalk.net/t300860

Apr 21 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by WindAndWaves | last post: by
4 posts views Thread by Bryan Tang | last post: by
5 posts views Thread by itsupport1 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.