How to connect Data Base Using Using Java or Selenium Webdriver
Data Base Code
import java.sql.*;
public class DatabaseConnectDemo{
public static void main(String[] args) throws Throwable {
//Resgister the driver through
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("registered driver successfully");
//Create the connection and assign to connection reference
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",
"username", "password");
System.out.println("connection successsfully");
//create a statement through connection reference and assign to statement reference
Statement stmt=con.createStatement();
System.out.println("statement object created successfully");
//call the executequery method through statement reference and pass the query as
argument.
ResultSet rs=stmt.executeQuery("select * from emp");
System.out.println("query is executed");
while(rs.next()){
int i=rs.getInt(1);
String str=rs.getString(2);
String str1=rs.getString(3);
int i1=rs.getInt(4);
System.out.println(i+"\t"+str+"\t"+str1+"\t"+i1);
import java.sql.*;
public class DatabaseConnectDemo{
public static void main(String[] args) throws Throwable {
//Resgister the driver through
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("registered driver successfully");
//Create the connection and assign to connection reference
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",
"username", "password");
System.out.println("connection successsfully");
//create a statement through connection reference and assign to statement reference
Statement stmt=con.createStatement();
System.out.println("statement object created successfully");
//call the executequery method through statement reference and pass the query as
argument.
ResultSet rs=stmt.executeQuery("select * from emp");
System.out.println("query is executed");
while(rs.next()){
int i=rs.getInt(1);
String str=rs.getString(2);
String str1=rs.getString(3);
int i1=rs.getInt(4);
System.out.println(i+"\t"+str+"\t"+str1+"\t"+i1);
}}}
0 comments:
Post a Comment