How you can add a counter to move the cursor to a specific location in the database (Column/Rows) so you can retrieve the data and use it in the method of (sendKeys)

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

How you can add a counter to move the cursor to a specific location in the database (Column/Rows) so you can retrieve the data and use it in the method of (sendKeys)

G A
How you can add a counter to move the cursor to a specific location in the database (Column/Rows) so you can retrieve the data and use it in the method of (sendKeys)
Presently in my code, I keep on adding rs.next() many times to get down in table until I get to the specific record in order to save it to string and use in Selenium coding (sendKeys)
I know that you can use (counter) but I haven't be able to make it work yet. 

Please is anybody tell me what I do have to change in my code to deploy the counter in order to give me the flexibility to navigate through the database table and retrieve the value that I wanted.

Thank you,

Ghassan 


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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())
// {

// String username2 = rs.getString("FirstName");
// System.out.println("This is my firstName " + username2);

// }

// while (rs.next()) {

// String username = rs.getString("FirstName");

// rs.next();
// Get the data from the second column (FirstName)
// System.out.println("This is the FirstName " + rs.getString(2));

// Get the data from the second column (LastName)
// System.out.println("This is the LastName " + rs.getString(1));

// }

// Get the first value FirstName in the column
rs.next();
String username = rs.getString("FirstName");
System.out.println("This is my firstName in the column " + username);

// Get the second value (FirstName) from the second column
rs.next();
String username1 = rs.getString("FirstName");
System.out.println("This is my seondName in the column " + username1);

// 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/ccf60bb9-8367-4bc9-989c-b6c23f26e844o%40googlegroups.com.