I need to update the the price of every track in the database. I am trying to do this by updating the the result set.When I try it without the ResultSet.TYPE_SCROLL_SENSITIVE, I get the error that this function is not implemented by the JDBC driver and when I include it I get an error that SQLite supports TYPE_FORWARD_ONLY cursors.
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();
}
Aucun commentaire:
Enregistrer un commentaire