0

I have a select query where i am retrieving column values like

select city,state,country from abc

and then fetching it using result set

city=rs.getString(1),state=rs.getString(2)

and so on

Now have to print like I live in city in state in country in java

can i give this way like

String a="I live in %city% in %state% in %country%"

will it work using %% symbol

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
user13763
  • 83
  • 7

3 Answers3

0

No, % wont work in java.. You have to concat strings..and our +(plus) operator do that job in java

String a="I live in "+city+" in "+state+" in "+country;
niiraj874u
  • 2,180
  • 1
  • 12
  • 19
0

you will have to use string concatenating operator + as below:

String a="I live in" +city+ "in" +state+ "in" +country;
Rahul
  • 3,479
  • 3
  • 16
  • 28
0
String a = "I live in " + city + " which is in " + state + " and in " + country + " Country";

Look at this tutorial for further details.

user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62
  • @user13763 because %% syntax is used in like operator in MYSQL not in JAVA – TruePS Apr 22 '14 at 06:19
  • In string literals if you want to add some data in between then you ll have to use `+` to concate the string. and as per @TruePS %% is used to match any part /place of word in MySql or Postgresql with `like` or `ilike`. If you want to use it then you will have to use `String.format`. – user3145373 ツ Apr 22 '14 at 06:20
  • @user13763 : see this link http://stackoverflow.com/questions/3695230/how-to-use-java-string-format – user3145373 ツ Apr 22 '14 at 06:22