Created
December 10, 2013 10:16
-
-
Save MedinskyAlexander/7888483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example; | |
import com.mysql.jdbc.Driver; | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.util.Properties; | |
public class ConnectionManager { | |
static Connection con; | |
static String url; | |
public static Connection getConnection() { | |
// work | |
// url = "jdbc:mysql://127.0.0.1:3306/mydb?user=root&password=1234"; | |
url = "jdbc:mysql://127.0.0.1:3306/mydb"; | |
//home | |
// url = "jdbc:mysql://127.0.0.1:3306/mydb?user=user&password=1234"; | |
// url = "jdbc:mysql://127.0.0.1:3306/mydb"; | |
try { | |
// try { | |
// Class.forName("com.mysql.jdbc.Driver"); | |
// } catch (ClassNotFoundException e) { | |
// System.out.println("\nDriver not found....\n"); | |
// e.printStackTrace(); | |
// } | |
Driver dr = new com.mysql.jdbc.Driver(); | |
Properties properties = new Properties(); | |
properties.put("user","root"); | |
// properties.put("user","user"); | |
properties.put("password","1234"); | |
con = dr. connect(url,properties); | |
// con = DriverManager.getConnection(url); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} | |
return con; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment