Hi Guys,
i am using postgresql 8.1 and using "postgresql8.1-405.jdbc.jar" i have written following code :-
package postGresConn;
import java.beans.Statement;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author OMKAR
*
*/
public class DbConn {
/**
* @param args
*/
public static void main(
String[] args) {
try {
System.out.println("Inside void main");
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnfe) {
System.err.println("Couldn't find driver class:");
cnfe.printStackTrace();
}
String jdbcConnString = "jdbc:postgresql://localhost/arrkdb";
Connection c = null;
try
{
c = DriverManager.getConnection(jdbcConnString,"postgres","postgres");
java.sql.Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT * from user_master");
while(rs.next())
{
System.out.println(" "+rs.getString("um_user_first_name"));
}
rs.close();
s.close();
c.close();
}
catch(SQLException sqe)
{
System.out.println("Could NOt establish connection \n"+sqe.getStackTrace());
}
}
}
************************************************************
Now, How can i get result of query like :-
"SELECT count(*) from user_master" which returns no of rows ???
The return Type of "executeQuery()" is ResultSet and not "int" ...then how do i get no of rows ? ....Above query works perfectly fine when executed in Query Analyser of Postgres !
Please Some one help !!
Thanks in advance !!