Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. public class Database {
  2. private static Database db;
  3. private Connection con;
  4.  
  5. public static Database getDB() throws Exception{
  6.     if(db == null)
  7.         db = new Database();
  8.     return db;
  9. }
  10.  
  11. private Database() throws Exception{
  12. Class.forName("com.mysql.jdbc.Driver");
  13. String connectionUrl = "jdbc:mysql://localhost:3306/psoftware?user=sdUsers"
  14.                     +"&password=sistemeD";
  15.   con = DriverManager.getConnection(connectionUrl);
  16. }
  17.  
  18. public ResultSet executeQuery(String query) throws Exception{
  19.     Statement stmt = con.createStatement();
  20.     return stmt.executeQuery(query);
  21. }
  22.  
  23. public PreparedStatement prepareStatement(String query) throws Exception{
  24.     return con.prepareStatement(query);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement