aspose file tools*
The moose likes JDBC and the fly likes Fail to convert to internal representation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Fail to convert to internal representation" Watch "Fail to convert to internal representation" New topic
Author

Fail to convert to internal representation

Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
Hi,

I am getting this error when i am trying to read records from the Data base.

java.sql.SQLException: Fail to convert to internal representation

The part of the code which i want to execute is :

try
{
Statement stmt = con.createStatement();
ResultSet rs= stmt.executeQuery("select * from employee");
while(rs.next())
{
String name=rs.getString("name");
int Empno =rs.getInt(2);
int class1=rs.getInt(3);
System.out.println(name);
System.out.println(Empno);
System.out.println(class1);
}
}

Please let me know what is the mistake done by me......

Thanks,
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

What are the data types of these three fields in your table?


Swastik
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

This means you are trying to get a specific field of one data type as an object that can't support that type. i.e. you are calling rs.getInt() for a field that is a date or something or other.

Its good practive to select specific field names in your select statement, this way your Java code does not have to change if thetable definition is altered. So I'd change your query to:

(Obviously you will have to correct the column names if these are not what they are)

Then check the data types of those fields. Is name a character dataype? Are both empno and class1 numeric? Are they both integers?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
I have my table definition like this:

NAME CHAR(30)
EMPNO NUMBER(10)
CLASS CHAR(10)

And i am trying to fetch the values first name then the empno and then the class.

Please let me know where i went wrong?

Thanks,
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

The data type of class in your table is char type, but while retrieving you are using getInt and here the conversion is failing

i.e. int class1=rs.getInt(3);

should be

String class1=rs.getString(3)
Rosy Mary
Greenhorn

Joined: Jan 08, 2009
Posts: 16
oppps could not catch that .....

any whay thanks for all your help....

Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fail to convert to internal representation