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

problem while reading data from excel sheet

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i try to read data from excel sheet, iam getting null values eventhough data exist in the excel sheet.
Can anyone tell me what could be the problem?

here is the code......
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con1=DriverManager.getConnection("jdbcdbcRIVER={Microsoft Excel Driver (*.xls)};DBQ="+Path1+name1,user1,passwd1);


String query1="select * from "+tname;
st1=con1.createStatement();
rs1=st1.executeQuery(query1);

while (rs1.next())
{
String str_value1=rs1.getString(1);
String str_value2=rs1.getString(2);
String str_value3=rs1.getString(3);
String str_value4=rs1.getString(4);
String str_value5=rs1.getString(5);
String str_value6=rs1.getString(6);
String str_value7=rs1.getString(7);
System.out.print(str_value1+" ");
System.out.print(str_value2+" ");
System.out.print(str_value3+" ");
System.out.print(str_value4+" ");
System.out.print(str_value5+" ");
System.out.print(str_value6+" ");
System.out.print(str_value7+" ");

}
}
catch(Exception e)
{
e.printStackTrace();

}
..........................end of code.........
Excel sheet contains numeric data and text data..
example
first row: 10 20 30 ab 30 and so on

while retrieving data iam getting data as null, for example in the above case instead of "ab" iam getting as null..
tell me how to sort this problem.
 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhishek

see below shown is the small code snippet which i have used to get data
from excel sheet ,the filename is the user choosen file name and it works as expected.............


i hope it helps you to some extent.

Dhwani:>Winning is not important but it is the only thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic