• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

java.sql.SQLException: Fail to convert to internal representation- POI excel issue

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

My requirement is to establish a DB connection with Oracl Database 11g and query the column values for the DB table named emp_records_sp.For the below code,I am able to collect the value in result set and create the cells in excel sheet but the database table column values are not getting set for the respective column names as created in the excel sheet during the result set iteration process.

Each time during the execution of the rs, It ends up in the below error message.

Can anyone help if I am doing some mistake in the below code during execution of the code?

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



PROBLEMATIC CODE SNIPPET:

while(rs.next()){
System.out.println("Hi 3");
HSSFRow row = sheet.createRow((short)index);
System.out.println("Hi 4");
row.createCell((int)0).setCellValue(rs.getInt(1));







ACTUAL CODE :

Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select all emp_records.id, emp_records.category, emp_records.type,emp_records.city,emp_records.bu, from emp_records_sp;
System.out.println("Hi 1");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel Sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((int) 0).setCellValue("ID");
rowhead.createCell((char) 1).setCellValue("Category");
rowhead.createCell((char) 2).setCellValue("Type");
rowhead.createCell((int) 3).setCellValue("City");
rowhead.createCell((char) 4).setCellValue("BU");
System.out.println("Hi 2");
int index=1;
while(rs.next()){
System.out.println("Hi 3");
HSSFRow row = sheet.createRow((short)index);
row.createCell((int)0).setCellValue(rs.getInt(1));
row.createCell((char)1).setCellValue(rs.getString(2));
row.createCell((char)2).setCellValue(rs.getString(3));
row.createCell((int)3).setCellValue(rs.getInt(4));
row.createCell((char)4).setCellValue(rs.getString(5));
index++;
}
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

select all emp_records.id, emp_records.category, emp_records.type,emp_records.city,emp_records.bu, from emp_records_sp;


why have you used 'all' in select statement.. I dont think it is valid.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you put that code inside code tags?

Also, that lot won't compile, the executeQuery line is missing a closing quotes and bracket.

ALL is valid, but I'm not sure it's required is it? It's the default for a statement, so i's a bit redundant.

Can you post the full stack trace and message and highlight the exact line in your code the error is thrown from?
 
Foni kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you put that code inside code tags?

Also, that lot won't compile, the executeQuery line is missing a closing quotes and bracket.

ALL is valid, but I'm not sure it's required is it? It's the default for a statement, so i's a bit redundant.

Can you post the full stack trace and message and highlight the exact line in your code the error is thrown from?



Dave Tolls wrote:Can you put that code inside code tags?

Also, that lot won't compile, the executeQuery line is missing a closing quotes and bracket.

ALL is valid, but I'm not sure it's required is it? It's the default for a statement, so i's a bit redundant.

Can you post the full stack trace and message and highlight the exact line in your code the error is thrown from?



Hello,

Below is my entire code, and I am getting error as below upon execution of the code. Kindly suggest.

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

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are you really doing that in your catch block?
You should at the very least be doing e.printStackTrace().
Without it how do you know what errors you are getting?

Which of course begs the question of how you got that exception in your post.
 
Marshal
Posts: 27368
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm curious to know what you think "(char) 1" means there. I don't think it means what you think it means... but first let's see your explanation.
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic