-1

Is it possible to put variable values from the console inside a database query using Selenium WebDriver?

For example:

//Get the variable from console input
Scanner reader = new Scanner(System.in);
System.out.println("Enter a variable: "); 
String input_variable = reader.next();
reader.close();

//Then do something like this:
String query = "select (input_variable) from database_table";`
JeffC
  • 22,180
  • 5
  • 32
  • 55
  • 1
    It looks like you're trying to build a SQL query as a string, for which the linked duplicate is what you're looking for. That said, if it's possible for WebDriver to execute SQL queries against your database, your security model is completely broken. – Daniel Pryden Feb 20 '18 at 16:07
  • Hi Daniel. Your link fixed my issue. You're right, my question is a duplicate. Thank you. – Andrej Milojeski Feb 21 '18 at 08:03

1 Answers1

0

There are a few ways you can accomplish this.

String query = String.format("select %s from database_table", variable);

or

String query = "select " + variable.toString() + " from database_table";

are just two examples off the top of my head.

Andrew Allison
  • 1,122
  • 2
  • 13
  • 30