Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/prototypeeop","root","triala");
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery(sql);
- public class ConnectionManager {
- private static String url = "jdbc:mysql://localhost:3306/prototypeeop";
- private static String driverName = "com.mysql.jdbc.Driver";
- private static String username = "root";
- private static String password = "triala";
- private static Connection con;
- private static String urlstring;
- public static Connection getConnection() {
- try {
- Class.forName(driverName);
- try {
- con = DriverManager.getConnection(urlstring, username, password);
- } catch (SQLException ex) {
- // log an exception. fro example:
- System.out.println("Failed to create the database connection.");
- }
- } catch (ClassNotFoundException ex) {
- // log an exception. for example:
- System.out.println("Driver not found.");
- }
- return con;
- }
- }
- private Connection con = null;
- private Statement stmt = null;
- private ResultSet rs = null;
- con = ConnectionManager.getConnection();
- stmt = con.createStatement();
- rs = stmt.executeQuery(sql);
Add Comment
Please, Sign In to add comment