Skip to content

Instantly share code, notes, and snippets.

@rederlo
Last active September 16, 2015 02:08
Show Gist options
  • Save rederlo/20fffd15ced114f974f3 to your computer and use it in GitHub Desktop.
Save rederlo/20fffd15ced114f974f3 to your computer and use it in GitHub Desktop.
Examplo connection mysql java
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