【发布时间】:2010-11-08 09:57:31
【问题描述】:
在下面的代码中,手动插入了值:13 和 Aman。但我正在做的是读取一个文件,然后直到文件完成,我将其中的值插入到 mysql 数据库表中。
public class Main {
public static void main(String[] argv) throws Exception {
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");
Statement st = con.createStatement();
int val = st.executeUpdate("INSERT employee VALUES(" + 13 + "," + "'Aman'" + ")");
System.out.println("1 row affected");
}
}
我试图像这样使用每一行:
String query = "INSERT INTO home (home_no, arrival_time, duration, persons, price, origin_city) VALUES("+line+");";
我该怎么做?
【问题讨论】:
-
您希望从文件中读取值执行多少次查询?
-
我正在读取一个文件,然后写“line =br.readLine();”而 while (line!= null) { .....上面的代码行,然后是 s.executeupdate(query)....在我的文件中,有很多数据行。因此,无论我的文件正在读取什么,我都会将其保留在行中。