java中的字符串用法

LGA*_*GAP 0 java string concatenation

请考虑将下面代码中的URL分配给字符串

String link = "http://www.topix.com/rss/city/ellensburg-wa";
Run Code Online (Sandbox Code Playgroud)

我应该如何使用下面代码中的字符串而不是URL本身.

注意:我是java的初学者

 stmt.executeQuery("select url from urls where url='http://www.topix.com/rss/city/ellensburg-wa'");

 stmtR.executeUpdate("insert into urls values(21211,'http://www.topix.com/rss/city/ellensburg-wa','source',1,0)"
Run Code Online (Sandbox Code Playgroud)

Col*_*ert 7

如果要创建一个好的查询,请使用预准备语句

PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urls VALUES(?, ?, ?, ?)");
//Replace the **first** "?" by an "id" variable content (containing an **int**)
insertUrlStatement.setInt(1, id);
//Replace the **second** "?" by the "url" variable content (containing a **String**)
insertUrlStatement.setString(2, url);
//Two other setXxx();
insertUrlStatement.executeUpdate()
Run Code Online (Sandbox Code Playgroud)

  • 我同意; 虽然有些人可能会说这对初学者来说太难了,但这是*正确的方法.字符串连接"永远"是构建SQL查询的正确方法,这只是您应该从一开始就学到的东西. (6认同)