Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we have some placeholders in java for string as we have (?) in SQL prepared statement

Tags:

java

replace

Can i have placeholder for String java like we have in sql prepared statements?

Eg Conside that i have string St = "akkk ? la,ala ? " ,

now i want to set values of ? as i set it in sql prepared statement st.setStingValue(1,"akshay"); // do we have something like this? St.setStringValue(2,"anjaaa");

like image 788
akshay Avatar asked Feb 08 '11 06:02

akshay


People also ask

Which character is used as a placeholder in PreparedStatement?

The "?" character is used for a placeholder, you can define as many placeholders you want, as shown below: String SQL = SELECT * from STOCKS WHERE TICKER=?

What is placeholder SQL query?

A placeholder expression provides a location in a SQL statement for which a third-generation language bind variable will provide a value. You can specify the placeholder expression with an optional indicator variable.

What are placeholders in Java?

A Placeholder is a predefined location in a JSP that displays a single piece of web content at a time that is dynamically retrieved from the BEA Virtual Content Repository.


1 Answers

You can use String.format

String st = "akkk %s la,ala %s "; 
String result = String.format(st, "First Val", "Second Val");

Alternatively, you can use numeric positions

String st = "akkk %1$s la,ala %2$s "; 
String result = String.format(st, "First Val", "Second Val");
like image 156
The Scrum Meister Avatar answered Oct 12 '22 22:10

The Scrum Meister