Last active
September 16, 2015 02:08
-
-
Save rederlo/20fffd15ced114f974f3 to your computer and use it in GitHub Desktop.
Examplo connection mysql java
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 br.com.biblioteca.conn; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
public class ConexaoMysql { | |
private static String url = "jdbc:mysql://127.0.0.1/biblioteca"; | |
private static String user = "root"; | |
private static String password = ""; | |
public Connection getConnection() throws Exception{ | |
try { | |
String driverName = "com.mysql.jdbc.Driver"; | |
Class.forName(driverName); | |
return DriverManager.getConnection(url, user, password); | |
} catch (Exception e) { | |
throw new Exception("ERRRO DE CONEXÃO!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment