Using the snippet provided above I’m trying to retreive the - TopicsExpress



          

Using the snippet provided above I’m trying to retreive the contents of the Database table Person. I’ve already created the table using mysql. But as soon as I execute this I’m getting the following exception. ” SQL Exception: java.sql.SQLException: Operation not allowed after ResultSet closed ” The table created mysql> select *from Person; +———+—-+ | name | id | +———+—-+ | xyz | 5 | +———+—-+ package testapp; import java.sql.*; public class Main { public static void main(String[] args) { Statement stmt; ResultSet Results; String FirstName = null,Id = null,printrow; try { Class.forName(“com.mysql.jdbc.Driver”); String connectionUrl = “jdbc:mysql://localhost/mysql?” + “user=root&password=pwdpwd”; Connection con = DriverManager.getConnection(“jdbc:mysql://localhost/Customer”,”root”,”pwd”); String query=”Select *from Person”; stmt=con.createStatement(); Results=stmt.executeQuery(query); stmt.close(); boolean Records=Results.next(); if(!Records) { System.out.println(“No Data returned”); return; } else { do{ FirstName=Results.getString(1); Id=Results.getString(2); printrow=FirstName+” “+Id; System.out.println(printrow); }while(Results.next()); } } catch (SQLException e) { System.out.println(“SQL Exception: “+ e.toString()); } catch (ClassNotFoundException cE) { System.out.println(“Class Not Found Exception: “+ cE.toString()); } } }
Posted on: Tue, 05 Aug 2014 17:08:21 +0000

Trending Topics



Recently Viewed Topics




© 2015