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

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

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

G A

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:


FirstName

Frank

Joe

Sam

Preston


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 = "192.168.0.103";

String serverport = "1433";


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

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


/*------dbUsername----*/

String dbUsername = "Ghassan";


/*------dbPassword----*/

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------*/

Class.forName("com.mysql.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 (rs.next()) {


// Get the First Name column list in the Table

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


// Displays the First Name list in the Table

System.out.println(state);


}


// Close db connection

con.close();

}


}

--
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 https://groups.google.com/d/msgid/selenium-users/d6b15527-2c2d-40e3-ba10-e98c274ff8b8o%40googlegroups.com.