Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fail to convert to internal representation

 
Rosy Mary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the data types of these three fields in your table?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rosy Mary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1603
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oppps could not catch that .....

any whay thanks for all your help....

Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic