Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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

JDBC:SQL Exception no data found

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;

public class ExcelReader
{

/**
* @param args
*/

public static void main(String[] args)
{
// TODO Auto-generated method stub
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dsnName = "ID";
String str = "jdbc:odbc:"+dsnName;
Connection con = DriverManager.getConnection(str);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("Select * from [sheet1$]");

ResultSetMetaData rsmd = rs.getMetaData();
rs.last();
int row_count = rs.getRow();
int column_count = rsmd.getColumnCount();
//int row_count = rsmd.get
System.out.println("Column count" + column_count);
System.out.println("Row count" + row_count);
//String arr_val;
rs.beforeFirst();
//String arr_col[] = new String{"LastName","FirstName","ID"};
String arr_val[][] = new String[row_count][column_count];
//rs.next();
while(rs.next())
{
for(int i=1;i<=row_count;i++)
{
for(int j=1;j<=column_count;j++)
{
arr_val[i-1][j-1] = rs.getString(j);
System.out.print("\t"+arr_val[i-1][j-1]);
}
}
System.out.println();
}
rs.close();
stmt.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
/* finally
{
con.close();
}*/
}

}
This is my code, wherein I am trying to fetch data from excel sheet and store it in 2d array. I am able to read in first row of excel sheet but while reading 2nd row, code is giving me run time error of


Output:Column count3
Row count2
Oswal Rocky 101.0
java.sql.SQLException: No data found
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at ExcelReader.main(ExcelReader.java:43)
Can anybody help me where I am going wrong, also, I have called rs.getString() only once then why this problem.

Please help me at the earliest.

Thanks in advance.
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
author & internet detective
Posts: 41914
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many columns are in that row in the actual spreadsheet?
 
rocky oswal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are 7 rows in the table
reply
    Bookmark Topic Watch Topic
  • New Topic