If I have a java code that deals with database and I want to use multi-threading in my application. Each thread suppose to run a function that contains insertion to the database. My question is: Where should I place the following statements:
Connection con = DriverManager.getConnection (dbUrl);
query = " insert into schema.table values (default,?,?)";
preparedStmt = con.prepareStatement(query);
Should I place them in the run so every thread execute them? or in the Main so they are executed once only? or inside the function that is called by the run function ? I need to know the right method to insert to Database when I have multi-threads. Thanks.