我需要更新数据库中每个曲目的价格。 我试图通过更新结果集来做到这一点。当我在没有ResultSet.TYPE_SCROLL_SENSITIVE的情况下尝试它时,我得到的错误是JDBC驱动程序没有实现此功能,当我包含它时,我得到一个SQLite支持TYPE_FORWARD_ONLY的错误光标。
private static void update_track_price_batch() {
// TODO Auto-generated method stub
System.out.println("Enter the % value between 100 and -100");
Scanner percentage_input = new Scanner(System.in);
float percentage = percentage_input.nextFloat();
float change = 100 + percentage ;
Connection myConn = null;
try
{
myConn = DriverManager.getConnection("jdbc:sqlite:chinook.db");
myst = myConn.prepareStatement("select * from Track", ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet myres = myst.executeQuery();
while (myres.next())
{
float f = myres.getFloat("UnitPrice");
int row_id = myres.getInt("TrackId");
myres.updateFloat("UnitPrice", f*change);
myres.updateRow();
}