我在 mysql 中创建了一个表,其中有一列“Sno”。并在“Sno”列中插入 1 到 10。我想根据 Sno 更新列值,但无法做到。请帮我。谢谢你。
这是我的代码。
int o=2,q=0;
ResultSet rs = st7.executeQuery("select * from table");
ResultSetMetaData metadata = rs.getMetaData();//here is columns are added dynamically,So that is metadata is needed.
BufferedReader br1 = new BufferedReader(new FileReader(f1));//here f1 is csv file path.
while ((line1 = br1.readLine()) != null) {
String[] splits = line1.split(",");//splitting line by ',' and storing into array.
n1 = splits.length;
for (m = 0; m < n1; m++) {
st8.executeUpdate("UPDATE table SET " + metadata.getColumnName(o) + "='" + splits[m] + "' WHERE Sno='"+q+"'");
o++;
}
q++;
out.println("<br>");
}
表结构
+--------+--------+--------+--------+---------+-----------+
|Sno | col1 | col2 | col3 | col4 | col5 |
+--------+--------+--------+--------+---------+-----------+
| 0 | NULL | NULL | NULL | NULL | NULL |
+--------+--------+--------+--------+---------+-----------+
| 1 | NULL | NULL | NULL | NULL | NULL |