File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes problem while reading data from excel sheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem while reading data from excel sheet" Watch "problem while reading data from excel sheet" New topic
Author

problem while reading data from excel sheet

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
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.


Abhishek
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
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.
 
Consider Paul's rocket mass heater.
 
subject: problem while reading data from excel sheet