Lokendra Bohra
Lokendra Bohra

Reputation: 3

Modifying String taken from database with input taken from textfield

I have a table in mysql database having only 2 column (Serial No and Statements) In statements I have Statements like :

( My name is _ )

I have to replace _ from the word taken from jtextfield. I tried to do using PreparedStatement

(used ? instead _ )

Suppose i typed Jack in jtextfield. The Output was:

(My name is 'Jack' )

I dont want the inverted commas! Help Please!

Upvotes: 0

Views: 36

Answers (1)

Akash Thakare
Akash Thakare

Reputation: 23002

If you want to update _ of statement in your database with the text typed in your text field.

You can use UPDATE query with replace

UPDATE demoTable SET statement = REPLACE(statement, '_', 'YourName');

If you have retrieved statement from database successfully and want to replace _ with name in java program. You should use replace method of String in java.

FOR EXAMPLE

String statement = "Hi, _";
String name = "Mike";
String yourString = statement.replace("_", name);
System.out.println(yourString);

OUTPUT

Hi, Mike

Upvotes: 1

Related Questions