Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package personas.jdbc;
- import com.mysql.cj.jdbc.Driver;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.TimeZone;
- /**
- *
- * @author marti
- */
- public class Conexion {
- private static final String JDBC_DRIVER="com.mysql.cj.jdbc.Driver";
- private static final String JDBC_URL="jdbc:mysql://localhost:3306/sga?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=" + TimeZone.getDefault().getID();
- private static final String USER="root";
- private static final String PASS="admin";
- private static Driver driver=null;
- public static synchronized Connection getConnection() throws SQLException{
- if (driver== null){
- try{
- Class driverJDBC=Class.forName(JDBC_DRIVER);
- driver=(Driver)driverJDBC.newInstance();
- DriverManager.registerDriver(driver);
- }catch (Exception e){e.printStackTrace();}
- }
- return DriverManager.getConnection(JDBC_URL, USER, PASS);
- }
- }
Add Comment
Please, Sign In to add comment