Hello,I am a fresh man to study the DB2.An error occured when I try t
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","830401");
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);
}
}
}
-------------------
--
TurboDis
situ - 20 Apr 2006 09:38 GMT
may be you are refering to the object which does not exist,
check out the table and column name you are useing
Gert van der Kooij - 20 Apr 2006 09:43 GMT
> 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.
TurboDisk - 20 Apr 2006 13:58 GMT
Thanks to everybody.But I don't know how to modify it
--
TurboDis
Phil Sherman - 20 Apr 2006 16:58 GMT
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
> Hello,I am a fresh man to study the DB2.An error occured when I try to
> Run a Java class.
[quoted text clipped - 62 lines]
>
> --------------------
TurboDisk - 21 Apr 2006 10:51 GMT
Thanks very much Phil.Thanks very much everybody
--
TurboDis