Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package DB;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.util.Enumeration;
  6. import java.util.Vector;
  7.  
  8. import com.mysql.jdbc.Connection;
  9. import com.mysql.jdbc.PreparedStatement;
  10. import com.mysql.jdbc.Statement;
  11.  
  12. public class Connexion {
  13. String driver="com.mysql.jdbc.Driver";
  14. Connection con;
  15. PreparedStatement pst;
  16. Statement st;
  17.  
  18. public Connection connecter()
  19. {
  20. try
  21. {
  22. Class.forName(driver);
  23. con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/gestion","root","");
  24. return con;
  25. }
  26. catch(Exception e)
  27. {
  28. e.printStackTrace();
  29. return null;
  30. }
  31. }
  32.  
  33. public ResultSet getalldatast(String req)
  34. {
  35. try
  36. {
  37. con=connecter();
  38. Statement st=(Statement)con.createStatement();
  39. ResultSet rs=st.executeQuery(req);
  40. return rs;
  41.  
  42. }
  43. catch(Exception e)
  44. {
  45. return null;
  46. }
  47. }
  48.  
  49. public ResultSet getalldatapst(String req,Vector<String> V)
  50. {
  51. try
  52. {int i = 1;
  53. con=connecter();
  54. PreparedStatement ps=(PreparedStatement) con.prepareStatement(req);
  55. Enumeration<String> eEnum=V.elements();
  56. while(eEnum.hasMoreElements())
  57. {
  58. ps.setString(i,eEnum.nextElement());
  59. i++;
  60. }
  61.  
  62.  
  63. ResultSet rs =ps.executeQuery();
  64. return rs;
  65.  
  66. }
  67. catch(Exception e)
  68. {
  69. System.out.println(e.getMessage());
  70. return null;
  71. }
  72. }
  73.  
  74. public int misejour(String req,Vector<String>V)
  75. {
  76. try
  77. {
  78. int i = 1;
  79. con=connecter();
  80. PreparedStatement pst=(PreparedStatement) con.prepareStatement(req);
  81. Enumeration<String> eEnum=V.elements();
  82. while(eEnum.hasMoreElements())
  83. {
  84. pst.setString(i,eEnum.nextElement());
  85. i++;
  86. }
  87.  
  88.  
  89. int a=pst.executeUpdate();
  90. return a;
  91. }
  92. catch(Exception e)
  93. { System.out.println(e.getMessage());
  94.  
  95. return 0;
  96. }
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement