Java MessageFormat - How can I insert values between single quotes?

I just tried double quotes and it worked fine for me:

MessageFormat messageFormat = new MessageFormat("insert into {0} values ( ''{1}'', ''{2}'', ''{3}'', {4} )");
Object[] args = {"000", "111", "222","333","444","555"};
String result = messageFormat.format(args);

The result is:

insert into 000 values ( '111', '222', '333', 444 )

Is this what you need?


Sorry if this is off the side, but it looks like you're trying to replicate the PreparedStatement that is already in JDBC.

If you are trying to create SQL to run against a database then I suggest that you look at PreparedStatement, it already does what you're trying to do (with a slightly different syntax).

Sorry if this isn't what you are doing, I just thought I would point it out.