我有一个简单的代码,可以将一些信息发送到 mysql。
Connection connection = null;
Statement stmt;
Properties connInfo = new Properties();
connInfo.put("user", "Main");
connInfo.put("password", "poiuyt");
connection = DriverManager.getConnection("jdbc:mysql://localhost/ABCNews", connInfo);
String sql = "insert into abcnews_topics VALUES (null, '" + text_topic + "');";
stmt = (Statement) connection.createStatement();
stmt.executeUpdate(sql);
“text_topic”它是我的信息的变量。这段代码我在循环中,并且在每一步中我的变量(text_topic)的值都会发生变化。
我想用准备好的陈述代替我的决定。怎么做?