Java Mysql Exception -
i'm getting exception in query inserting data database, inserting lot of data database around 15k lines. exception message:
the driver unable create connection due inability establish client portion of socket.this caused limit on number of sockets imposed operating system. limit configurable.
my function insert query:
public static void insertobject(int modelid,float x,float y,float z,float rx,float ry,float rz){ try { con = drivermanager.getconnection(url, user, password); string query = " insert wastobjects (modelid,x,y,z,rx,ry,rz)" + " values (?, ?, ?, ?, ?, ?, ?)"; preparedstatement preparedstmt = con.preparestatement(query); preparedstmt.setint (1, modelid); preparedstmt.setfloat (2, x); preparedstmt.setfloat (3, y); preparedstmt.setfloat (4, z); preparedstmt.setfloat (5, rx); preparedstmt.setfloat (6, ry); preparedstmt.setfloat (7, rz); preparedstmt.execute(); con.close(); } catch (exception e) { system.err.println("got exception!"); system.err.println(e.getmessage()); } }
you can reuse connection instead of creating new 1 each time need insert new row.
and try close prepared statement , connection in finally
block.
for example:
connection con = null; preparedstatement ps = null; try { // code here. ps.execute(); con.commit(); } catch (exception e){ } { closeresource(ps) closeresource(con); }
your new method:
private void closeresource(autocloseable resource) { if (resource != null) { try { resource.close(); } catch (exception e) { } } }
that's why when exception resources won't close , reach limit of sockets.
Comments
Post a Comment