• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Foni kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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++;
}
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • 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.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!