Following script will explain how to create connection with database and fetch the values
public class DB_Connection_SQL {
public static String url = "jdbc:sqlserver://000.000.0.000:0000;DatabaseName=TEST_DB" ;
public static void main(String [] args){
Connection con = DriverManager.getConnection(url,"UN","PWD");
// Create statement object which should use SQL statement.
Statement stmt = con.createStatement();
// Send SQL SELECT statements to the database which returns the //requested information as rows of data in a Result Set object.
ResultSet res = stmt.executeQuery( "select top 1 name from Emp" );
// Fetch value of "name" from "result" object.
String Ename = res.getString( "name" );
// Use the email Address value to login to application.
selenium.type( "userID" , Ename);
}
}
Note:Below are should import to run above script
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
No comments:
Post a Comment