/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication2; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * * @author scottjf */ public class ProcedureExecuter { Connection connection = null; int id = 0; public ProcedureExecuter(Connection connection, int id){ // If you uncomment out this section, the error stops happening, but then we are // not using multi threads on a single connection // try { // Class.forName("org.mariadb.jdbc.Driver").newInstance(); // connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root1", "root1"); // //multiple clients (windows) will use this connection to get unique callable statements. // connection.setAutoCommit(true); // } catch (Exception ex) { // ex.printStackTrace(); // } this.connection = connection; this.id = id; } public void log(String string){ CallableStatement cStmt = null; try { cStmt = connection.prepareCall("{call addLog(?,?,?,?)}"); cStmt.setString("pName", "testLog"+id); cStmt.setString("pUser", "ME"+id); cStmt.setInt("pSeverity", 1); cStmt.setString("pLogInfo", id+string); cStmt.executeUpdate(); } catch (SQLException ex) { ex.printStackTrace(); } finally { if (cStmt != null) { try { cStmt.close(); } catch (SQLException sqle) { } } } } public void startTest(int count){ for(int i = 0; i<5; i++){ changeState("me@"+count, "title@"+count, "info@"+count,i); log("finished testing log"+count+"@"+i); } } public void changeState(String user, String title, String something,int counter ){ CallableStatement cStmt = null; try { cStmt = connection.prepareCall("{call saveLoc(?,?,?,?,?,?,?,?,?)}"); cStmt.setString(1 , user+id); cStmt.setString(2 , title+id); cStmt.setString(3 , "test"+id); cStmt.setInt(4 , 200+counter); cStmt.setInt(5 , 300+counter); cStmt.setInt(6 , 400+counter); cStmt.setInt(7 , 500+counter); cStmt.setInt(8 , 600+counter); cStmt.setString(9 , "CANNOT_BE_PINNED" ); cStmt.executeUpdate(); log("saveLoc completed for "+user+id+" @ "+counter); } catch (SQLException ex) { ex.printStackTrace(); } finally { if (cStmt != null) { try { cStmt.close(); } catch (SQLException sqle) { } } } } }