Connecting to DataBase using Selenium WebDriver

Selenium Webdriver Script to connect postgresql database.

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 {
  Connection con = DriverManager.getConnection(dbUrl,username,password);
  System.out.println("Connected to database");
                Statement stmt =con.createStatement();
  ResultSet rs = stmt.executeQuery("select id from emp");
  while ( {
                int x = rs.getInt("id");
                System.out.println("Employee ids="+ x);
  System.out.println("Connection closed");


Output:-Displays all employee ids.


No comments:

Related Posts Plugin for WordPress, Blogger...