java - JDBC: safe row update when multiple requests -


i have java restful api uses jdbc combopooleddatasource connection pooling (http://www.mchange.com/projects/c3p0/), , preparedstatement updates row incrementing field:

public void update(int messageid) {      string update_stm = "update table set count_field = count_field +1 id=?";     conn = connectionmanager.getconnection();     preparedstatement stm = conn.preparestatement(update_stm );     stm.setint(1, messageid);     stm.executeupdate(); } 

(i've omitted try/catch, , connectionmanager.getconnection() gives me 1 of available connections pool). if restful service receives 2 or more requests update() method @ same time, granted count updated correctly? if not, how should modify code avoid wrong count update?

use innodb

as far can see, java code thread-safe, doesn't access or change fields. have worry update action on database side. assume using mysql, since have tagged question mysql tag. mysql dbms offers acid model, need set database engine innodb work. more details see link.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -