Hi I am writing a simple program in Netbeans. Also when I run my code in Notepad it works fine.
Below is the code
public class SQLConnection {
String url= "jdbcdbc:db1";
Statement stmt;
Connection Db;
SQLConnection() throws ClassNotFoundException, SQLException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Db = DriverManager.getConnection(url);
}
catch(Exception e)
{
System.out.println(e);
}
stmt = Db.createStatement();
ResultSet rs = stmt.executeQuery("Select * from login");
int col1 = rs.findColumn("name");
System.out.println(col1);
//boolean a;
// a = rs.first();
do
{
String name1 = rs.getString("name");
String name2 = rs.getString("last");
System.out.println(name1 + name2);
}
while(rs.next());
Db.close();
rs.close();
}
public static void main(String args[]) throws ClassNotFoundException, SQLException
{
SQLConnection sq = new SQLConnection();
}
}
IWhen i run the project it gives me below error
Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.j ava:3907)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Jdbc OdbcResultSet.java:5698)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbc ResultSet.java:354)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbc ResultSet.java:411)
at incident.manager.SQLConnection.<init>(SQLConnectio n.java:44)
at incident.manager.SQLConnection.main(SQLConnection. java:55)
Table name, database name happens to be alright..
Can anyone please help me with this...... I am stuck