3
我知道使用NetBeans將一行添加到sql數據庫的簡單方法。使用java在sql中添加多行
這裏是一個方法:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/zeeshan",
"root","sHaNi97426");
Statement stmt = (Statement)conn.createStatement();
String insert = "INSERT INTO clients VALUES('"+hostname+"');";
stmt.executeUpdate(insert);
現在,我想在sql數據庫添加多行。例如,代碼如下:
Process p = Runtime.getRuntime().exec("tasklist.exe");
BufferedReader s = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s.readLine()) != null) {
System.out.print(s.readLine());
}
我想添加的每一行的SQL直到s.readLine()
變得null
。
請幫助我。