Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://localhost:3306/project";
- Class.forName(driver);//load driver to memory
- Connection con = DriverManager.getConnection(url, "rootsql", "1234?");
- if (con != null) {
- String sqlString = "INSERT INTO table_jobs(name,content,sd,ed,status,creation_date) values('"+name+"','"+content+"','"+sd+"','"+ed+"','"+status+"','"+creation_date+"');";
- Statement stmt = con.createStatement();
- idreturned = stmt.executeUpdate(sqlString , Statement.RETURN_GENERATED_KEYS);
- ResultSet rs = stmt.getGeneratedKeys();
- if (rs.next()){
- idreturned = rs.getInt(1);
- }
- rs.close();
- // here i try to insert the job for each worker for my third table
- String[] ary = ary_workers.split("-");
- if (ary.length>0){
- StringBuilder sb = new StringBuilder(ary_workers);
- Statement stm2 ;
- String sqlString2 ;
- for (int i = 0 ; i < ary.length ; i++ ){
- sqlString2 = "INSERT INTO table_ids(idtable_jobs,idtable_workers) values('"+idreturned+"','"+1+"');";
- stm2 = con.createStatement();
- stm2.execute(sqlString2);
- }
- }
- con.close();
- return "genrated = "+ idreturned;
- }
- if (con == null) {
- return "no connection";
- }
- } catch (Exception e) {
- e.getLocalizedMessage();
- outst = e.toString();
- }
- return outst;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement