Guest User

Untitled

a guest
Jan 3rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. try
  2. {
  3. Class.forName("com.mysql.jdbc.Driver");
  4. Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/prototypeeop","root","triala");
  5. Statement stmt=con.createStatement();
  6. ResultSet rs=stmt.executeQuery(sql);
  7.  
  8. public class ConnectionManager {
  9. private static String url = "jdbc:mysql://localhost:3306/prototypeeop";
  10. private static String driverName = "com.mysql.jdbc.Driver";
  11. private static String username = "root";
  12. private static String password = "triala";
  13. private static Connection con;
  14. private static String urlstring;
  15.  
  16. public static Connection getConnection() {
  17. try {
  18. Class.forName(driverName);
  19. try {
  20. con = DriverManager.getConnection(urlstring, username, password);
  21. } catch (SQLException ex) {
  22. // log an exception. fro example:
  23. System.out.println("Failed to create the database connection.");
  24. }
  25. } catch (ClassNotFoundException ex) {
  26. // log an exception. for example:
  27. System.out.println("Driver not found.");
  28. }
  29. return con;
  30. }
  31. }
  32.  
  33. private Connection con = null;
  34. private Statement stmt = null;
  35. private ResultSet rs = null;
  36.  
  37. con = ConnectionManager.getConnection();
  38. stmt = con.createStatement();
  39. rs = stmt.executeQuery(sql);
Add Comment
Please, Sign In to add comment