• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC:SQL Exception no data found

 
rocky oswal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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 = "jdbcdbc:"+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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
There are 7 rows in the table
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic