• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fail to convert to internal representation

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the data types of these three fields in your table?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oppps could not catch that .....

any whay thanks for all your help....

Thanks,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic