JAVA JDBCデータベースの一点記録:ResultSet
JAVA JDBCデータベースの一点記録:ResultSet
Statement stmt =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String table = "Student";
String sql = "SELECT * FROM "+table;
ResultSet rs = stmt.executeQuery(sql);
public static void printData(ResultSet rs) throws SQLException
{
rs.beforeFirst();
System.out.println("NO name age add");
while(rs.next())
{
int NO = rs.getInt("NO");
String name = rs.getString("name");
int age = rs.getInt("age");
String add = rs.getString("add");
System.out.println(NO+" "+name+" "+age+" "+add);
}
}
public static void updateData(ResultSet rs) throws SQLException
{
rs.first();
rs.updateString("name", "ken");
rs.updateInt(3, 10);
rs.updateRow();
rs.moveToInsertRow();
rs.updateInt(1, 8);
rs.updateString(2, "Tim");
rs.updateInt(3, 28);
rs.updateString(4,"china");
rs.insertRow();
rs.moveToCurrentRow();
}
public static void delData(ResultSet rs,int rowid) throws SQLException
{
rs.absolute(rowid);
rs.deleteRow();
}