hgbdelphi
asked on
how can i do like PreparedStatement.setString(1,'a'),PreparedStatement.setString(2,'b')?
hi,experts,i want do this like PreparedStatement.setStrin g(1,'a'),P reparedSta tement.set String(2,' b')
String s="select * from tab1 where a=? and b=? and c=?";
MyStringClass.setString(1, 'aaa');
MyStringClass.setString(3, 'ccc');
MyStringClass.setString(2, 'bbb');
and after setString();
s="select * from tab1 where a='aaa' and b='bbb' and c='ccc';
now i use String.replaceFirst("\\?", s);
but if i not sequence replace, it can not get right resutl,how can i do it?
thanks!
String s="select * from tab1 where a=? and b=? and c=?";
MyStringClass.setString(1,
MyStringClass.setString(3,
MyStringClass.setString(2,
and after setString();
s="select * from tab1 where a='aaa' and b='bbb' and c='ccc';
now i use String.replaceFirst("\\?",
but if i not sequence replace, it can not get right resutl,how can i do it?
thanks!
ASKER
hi,aozarov
thanks for your help,this is my want
String s="select * from tab1 where a=? and b=? and c=?";
MyStringClass.setString(s, 1,'aaa');
MyStringClass.setString(s, 3,'ccc');
MyStringClass.setString(s, 2,'bbb');
and after setString();
s="select * from tab1 where a='aaa' and b='bbb' and c='ccc';
now i use String.replaceFirst("\\?", s);
but if i not sequence replace, it can not get right resutl,how can i do it?
thanks for your help,this is my want
String s="select * from tab1 where a=? and b=? and c=?";
MyStringClass.setString(s,
MyStringClass.setString(s,
MyStringClass.setString(s,
and after setString();
s="select * from tab1 where a='aaa' and b='bbb' and c='ccc';
now i use String.replaceFirst("\\?",
but if i not sequence replace, it can not get right resutl,how can i do it?
ASKER
now i don't know how do i write MyStringClass.setString()m ethod,now i use
String.replaceFirst("\\?", s);
but if i not sequence replace, it can not get right resutl,how can i do it?
String.replaceFirst("\\?",
but if i not sequence replace, it can not get right resutl,how can i do it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
replace: System.out.println(myStrin gClass.get Translated String());
with: System.out.println(myStrin gClass.get Translated Query());
The suggested code is instead of passing s to each method and having setString as a static method on MyStringClass.
with: System.out.println(myStrin
The suggested code is instead of passing s to each method and having setString as a static method on MyStringClass.
ASKER
hi,aozarov
thanks for your help!
it can work fine. best Regard!
thanks for your help!
it can work fine. best Regard!
NP :-)
There's already a class that does this:
String s="select * from tab1 where a={0} and b={1} and c={2}";
java.text.MessageFormat mf = new java.text.MessageFormat(s) ;
Object[] args = new Object[3];
args[0] = "'aaa'";
args[2] = "'ccc'";
args[1] = "'bbb'";
System.out.println(mf.form at(args));
String s="select * from tab1 where a={0} and b={1} and c={2}";
java.text.MessageFormat mf = new java.text.MessageFormat(s)
Object[] args = new Object[3];
args[0] = "'aaa'";
args[2] = "'ccc'";
args[1] = "'bbb'";
System.out.println(mf.form
>> There's already a class that does this:
Yes, but that requires a different syntax (instead of unordered "?" to have ordered "{..}")
Yes, but that requires a different syntax (instead of unordered "?" to have ordered "{..}")
>>Yes, but that requires a different syntax (instead of unordered "?" to have ordered "{..}")
I don't understand your point ...
I don't understand your point ...
>> I don't understand your point ...
My point is that "select * from tab1 where a={0} and b={1} and c={2}"
doesn't use the syntax used by PreparedStatement
"select * from tab1 where a=? and b=? and c=?"
which might be part of the requirements.
My point is that "select * from tab1 where a={0} and b={1} and c={2}"
doesn't use the syntax used by PreparedStatement
"select * from tab1 where a=? and b=? and c=?"
which might be part of the requirements.
StringTokenizer stTokens = new StringTokenizer(s, "?", true);
int index = 1;
StringBuffer result = new StringBuffer();
while (stTokens.hasMoreTokens())
{
String token = stTokens.nextToken();
if ("?".equals(token))
{
result.append(map.get(new Integer(index)));
index++;
}
else
{
result.append(token);
}
}
System.out.println(result.
}