Created
October 28, 2013 07:34
-
-
Save Makistos/7192719 to your computer and use it in GitHub Desktop.
This little function will create a connection to a MySql database in the local machine. Database and user name and password are supplied as parameters. #mysql #java
This file contains hidden or 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
private void initDb(String db, String user, String pw) { | |
String url = "jdbc:mysql://localhost/" + db; | |
try { | |
Class.forName("com.mysql.jdbc.Driver").newInstance(); | |
con = DriverManager.getConnection(url, user, pw); | |
if (con.isClosed()) { | |
System.err.println("Failed to connecto to " + db); | |
} | |
} | |
catch (Exception e) { | |
System.err.println("Exception: "+ e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment