我假設你的意思是一個簡單的插入;
首先你的數據庫連接,就像這樣:
public class DBConnection {
final private String url = "jdbc:mysql://localhost/";
final private String databaseName = "test";
final private String user = "root";
final private String password = "159753";
public Connection Connect() {
Connection c = null;
try {
c = DriverManager.getConnection(url + databaseName, user, password);
} catch (SQLException ex) {
Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
}
return c;
}}
下面是插入一個簡單的例子:
public static void main(String[] args) {
Connection con = new DBConnection().Connect();
String sql = "INSERT INTO nameTable (name) values (?)";
PreparedStatement stmt;
try {
stmt = con.prepareStatement(sql);
List<String> names = new ArrayList();
names.add("John");
names.add("Sally");
names.add("Rob");
for (String name : names) {
stmt.setString(1, name);
stmt.execute();
}
stmt.close();
con.close();
} catch (SQLException ex) {
System.err.println("Error = " + ex);
}
}}
PS:不過你可以用一個Java持久性API也。 wikibook是一個很好的資源作爲參考
你如何定義「行」?記錄是否有一個定義行號的數字主鍵?而且,除了數組*以外,*其他值,這是什麼意思?你能提供更豐富的例子嗎? – lurker