How to save a database record located in a specific row into a string

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How to save a database record located in a specific row into a string


Hi everyone:

   I am new to selenium and I did created a code to open MS SQL connation to database and displays the first row in the table which have all the First Names so now I would like to save each of the names in the database record into different string so I can use the selenium code (sendKeys) to test the different First Name in HTML application

After I executed the code, I got the output:






My java Code is 

package Test;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class AAA {

public static void main(String[] args) throws ClassNotFoundException, SQLException {

String dbName = "World2";

String serverip = "";

String serverport = "1433";

/*------connection url----*/

String dbUrl = "jdbc:sqlserver://" + serverip + "\\SQLEXPRESS:" + serverport + ";databaseName=" + dbName + "";


String dbUsername = "Ghassan";


String dbPassword = "root";

/*------db query---*/

// String query = "SELECT FirstName\r\n" + "FROM dbo.Testing\r\n" + "ORDER BY

// FirstName\r\n" + " OFFSET 1 ROWS";

String query = "Select * from dbo.Testing";

/*-----load Microsoft SQL jdbc driver------*/


/*----Get connection to DB*/

Connection con = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);

// create statement object

Statement stmt = con.createStatement();

// send sql query to database

ResultSet rs = stmt.executeQuery(query);

// while loop to get ResultSet all rows data

while ( {

// Get the First Name column list in the Table

String state = rs.getString("FirstName");

// Displays the First Name list in the Table



// Close db connection




You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit