Guest User

Untitled

a guest
Mar 5th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.logging.Level;
  3. import java.util.logging.Logger;
  4.  
  5.  
  6. public class QueryTesting
  7. {
  8.  
  9. public static void main(String[] args)
  10. {
  11. try
  12. {
  13. // create a java mysql database connection
  14. Class.forName("com.mysql.jdbc.Driver");
  15. try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/?verifyServerCertificate=false&useSSL=true", "username", "password")) {
  16. Statement s = null ;
  17. try {
  18. s = conn.createStatement();
  19. } catch (SQLException ex) {
  20. Logger.getLogger(QueryTestingForWMC.class.getName()).log(Level.SEVERE, null, ex);
  21. }
  22. int Result ;
  23. try {
  24. Result = s.executeUpdate("USE myDatabase");
  25. } catch (SQLException ex) {
  26. Logger.getLogger(QueryTestingForWMC.class.getName()).log(Level.SEVERE, null, ex);
  27. }
  28. PreparedStatement preparedStmt= null;
  29. // create the java mysql update preparedstatement
  30. String query = "update relativesTable set idRelativeMembers = ? , Name = ? , Picture = ? , RelationDegree = ? , persons_idPersons = ? where idRelativeMembers = ?";
  31. // create the mysql update preparedstatement
  32. preparedStmt = conn.prepareStatement(query);
  33. preparedStmt.setString(1,"00002/10");
  34. preparedStmt.setString(2,"عبد الحفيظ أحمد عبد الفتاح الدؤري");
  35. preparedStmt.setBinaryStream(3, null);
  36. preparedStmt.setString(4, "إبن عم");
  37. preparedStmt.setString(5, "00002");
  38. preparedStmt.setString(6, "00002/10");
  39. // execute the preparedstatement
  40. preparedStmt.executeUpdate();
  41. // execute the java preparedstatement
  42. preparedStmt.executeUpdate();
  43. preparedStmt.close();
  44. s.close();
  45. }
  46. catch (Exception e)
  47. {
  48. System.err.println("Got an exception! ");
  49. System.err.println(e.getMessage());
  50. }
  51. }catch (ClassNotFoundException e)
  52. {
  53. System.err.println("Got an exception! ");
  54. System.err.println(e.getMessage());
  55. }
  56.  
  57. }
  58. }
  59.  
  60. // the mysql update statement
  61. String selectedMemberPrimaryKey = getMembersWithoutPhotos().get(jTable5.convertRowIndexToView(jTable5.getSelectedRow())).getId() ;
  62.  
  63. System.out.println("This is an update query");
  64.  
  65. String updateStatement = "update relativesTable set idRelativeMembers = ? , Name = ? , Picture = ? , RelationDegree = ? , persons_idPersons = ? where idRelativeMembers = ?";
  66.  
  67. // create the mysql update preparedstatement
  68. preparedStmt = conn.prepareStatement(updateStatement);
  69. preparedStmt.setString(1, jTextField2.getText());
  70.  
  71. // the mysql insert statement
  72. System.out.println("This is an insert query");
  73.  
  74. String insertStatement = "insert into relativesTable (idRelativeMembers, Name, Picture, RelationDegree, persons_idPersons) values ( ?, ?, ?, ?, ?)";
  75.  
  76.  
  77. // create the mysql insert preparedstatement
  78. preparedStmt = conn.prepareStatement(insertStatement);
  79. preparedStmt.setString(1, jTextField2.getText());
  80.  
  81. select * from `information_schema`.`triggers`
  82. where event_object_schema = 'myDatabase'
  83. and event_object_table = 'relativesTable'G
Add Comment
Please, Sign In to add comment