Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DB;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.util.Enumeration;
- import java.util.Vector;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.PreparedStatement;
- import com.mysql.jdbc.Statement;
- public class Connexion {
- String driver="com.mysql.jdbc.Driver";
- Connection con;
- PreparedStatement pst;
- Statement st;
- public Connection connecter()
- {
- try
- {
- Class.forName(driver);
- con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/gestion","root","");
- return con;
- }
- catch(Exception e)
- {
- e.printStackTrace();
- return null;
- }
- }
- public ResultSet getalldatast(String req)
- {
- try
- {
- con=connecter();
- Statement st=(Statement)con.createStatement();
- ResultSet rs=st.executeQuery(req);
- return rs;
- }
- catch(Exception e)
- {
- return null;
- }
- }
- public ResultSet getalldatapst(String req,Vector<String> V)
- {
- try
- {int i = 1;
- con=connecter();
- PreparedStatement ps=(PreparedStatement) con.prepareStatement(req);
- Enumeration<String> eEnum=V.elements();
- while(eEnum.hasMoreElements())
- {
- ps.setString(i,eEnum.nextElement());
- i++;
- }
- ResultSet rs =ps.executeQuery();
- return rs;
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- return null;
- }
- }
- public int misejour(String req,Vector<String>V)
- {
- try
- {
- int i = 1;
- con=connecter();
- PreparedStatement pst=(PreparedStatement) con.prepareStatement(req);
- Enumeration<String> eEnum=V.elements();
- while(eEnum.hasMoreElements())
- {
- pst.setString(i,eEnum.nextElement());
- i++;
- }
- int a=pst.executeUpdate();
- return a;
- }
- catch(Exception e)
- { System.out.println(e.getMessage());
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement