Selenium Webdriver Scripts - Executing multiple sql queries using JDBC

package selenium_examples;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Database {
 public static void main(String[] args) throws ClassNotFoundException, SQLException {
  Class.forName("org.postgresql.Driver");
  Connection con = DriverManager.getConnection(dbUrl,username,password);
                //dbUrl="jdbc:postgresql://hostname:port/dbname"
  System.out.println("Connected to Database");
  Statement stmt =con.createStatement();
  Statement stmt1 =con.createStatement();
  ResultSet rs = stmt.executeQuery("select id from emp");
  ResultSet rs1 = stmt1.executeQuery("select deptno from dept");
 
  while (rs.next()) {
  
             int x = rs.getInt("id");
             System.out.println("id :"+ x);
 }
  while (rs1.next())
  {
  
            int z = rs1.getInt("deptno");
            System.out.println("deptno :"+ z);
 }
  con.close();
  System.out.println("Connection Closed");
 }

}


 

No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge