Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. "SELECT FROM * TABLE;INSERT INTO TABLE;"
  2.  
  3. String url = "jdbc:mysql://localhost:3306/";
  4. String dbName = "databaseinjection";
  5. String driver = "com.mysql.jdbc.Driver";
  6. String sqlUsername = "root";
  7. String sqlPassword = "abc";
  8.  
  9. Class.forName(driver).newInstance();
  10.  
  11. connection = DriverManager.getConnection(url+dbName, sqlUsername, sqlPassword);
  12.  
  13. "SELECT FROM * TABLE;INSERT INTO TABLE;"
  14.  
  15. String dbUrl = "jdbc:mysql:///test?allowMultiQueries=true";
  16.  
  17. boolean hasMoreResultSets = stmt.execute( multiQuerySqlString );
  18.  
  19. READING_QUERY_RESULTS: // label
  20. while ( hasMoreResultSets || stmt.getUpdateCount() != -1 ) {
  21. if ( hasMoreResultSets ) {
  22. Resultset rs = stmt.getResultSet();
  23. // handle your rs here
  24. } // if has rs
  25. else { // if ddl/dml/...
  26. int queryResult = stmt.getUpdateCount();
  27. if ( queryResult == -1 ) { // no more queries processed
  28. break READING_QUERY_RESULTS;
  29. } // no more queries processed
  30. // handle success, failure, generated keys, etc here
  31. } // if ddl/dml/...
  32.  
  33. // check to continue in the loop
  34. hasMoreResultSets = stmt.getMoreResults();
  35. } // while results
  36.  
  37. CallableStatement cstmt = con.prepareCall( "call multi_query()" );
  38. boolean hasMoreResultSets = cstmt.execute();
  39. READING_QUERY_RESULTS:
  40. while ( hasMoreResultSets ) {
  41. Resultset rs = stmt.getResultSet();
  42. // handle your rs here
  43. } // while has more rs
  44.  
  45. Statement s = c.createStatement();
  46. String s1 = "update emp set name='abc' where salary=984";
  47. String s2 = "insert into emp values ('Osama',1420)";
  48. s.addBatch(s1);
  49. s.addBatch(s2);
  50. s.executeBatch();
  51.  
  52. &
  53.  
  54. url="jdbc:mysql://localhost/glyndwr?autoReconnect=true&allowMultiQueries=true"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement