java中字符串的快速参数函数

发布于 2024-11-28 07:10:10 字数 416 浏览 1 评论 0原文

我是delphi程序员,很久以前就使用过Java,现在再次回到java项目中,我确信有一个函数或对象可以用来基本上创建一个带有参数的字符串,并且可以替换所述参数就像PreparedStatement一样。现在我一生都记不起这个函数叫什么,或者即使它存在于PreparedStatement之外还是我在想象事情???

例如,我想采用这样的字符串:

String ss = "(CODE, CATEGEORY, DESCRIPTION) VALUES (:CODE, :CATEGEORY, :DESCRIPTION)";

并且能够做到这一点

ss.setParam(0, "thisValue");
ss.setParam(1, "thus_value");

等等......

任何想法

Im delphi programmer and used to use Java quite a bit a long while ago and now back onto a project in java again and im sure that there was a function or object that could be used to basically create a string with parameters and would replace said params just like PreparedStatement. Now for the life of me i cannot remember what this function is called or even if it exists outside of PreparedStatement or am i imagining things ???

For example, i want to take a string like this:

String ss = "(CODE, CATEGEORY, DESCRIPTION) VALUES (:CODE, :CATEGEORY, :DESCRIPTION)";

and be able to do this

ss.setParam(0, "thisValue");
ss.setParam(1, "thus_value");

etc...

Any ideas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

行至春深 2024-12-05 07:10:10
MessageFormat mf = new MessageFormat(
    "(CODE, CATEGEORY, DESCRIPTION) VALUES ({0}, {1}, {2})");

System.out.println(mf.format("thisValue", "thatValue", "theOtherValue"));
MessageFormat mf = new MessageFormat(
    "(CODE, CATEGEORY, DESCRIPTION) VALUES ({0}, {1}, {2})");

System.out.println(mf.format("thisValue", "thatValue", "theOtherValue"));
隔岸观火 2024-12-05 07:10:10

你是对的,它们被称为PreparedStatements。

PreparedStatement pstmt = con.prepareStatement("INSERT INTO myTable " +
    "(CODE, CATEGORY, DESCRIPTION) VALUES (?, ?, ?)");
pstmt.setString(1, "thisValue")
pstmt.setString(2, "thus_value",
pstmt.setString(3, "My description");

http://download.oracle.com/javase/6 /docs/api/java/sql/PreparedStatement.html

You are right, they are called PreparedStatements.

PreparedStatement pstmt = con.prepareStatement("INSERT INTO myTable " +
    "(CODE, CATEGORY, DESCRIPTION) VALUES (?, ?, ?)");
pstmt.setString(1, "thisValue")
pstmt.setString(2, "thus_value",
pstmt.setString(3, "My description");

http://download.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html

花开浅夏 2024-12-05 07:10:10

您在谈论“StringBuffer”吗?如果是,您只需将查询附加到其中并创建查询即可。

Are you talking about 'StringBuffer' ? If yes, you can simply append your query to it and create a query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文