Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class DatabaseModel implements Model{
- private final static String HOST = "sql11.freesqldatabase.com";
- private final static int PORT = 3306;
- private final static String USER_DB = "sql11192316";
- private final static String PASS_DB = "l3dn9N16VL";
- public final static String DB = "sql11192316";
- public static Connection defaultConnection = null;
- public static Connection getDefaultConnection() throws SQLException{
- if( defaultConnection == null || defaultConnection.isClosed() )
- defaultConnection = newConnection();
- return defaultConnection;
- }
- public static Connection newConnection() throws SQLException {
- Connection connection = null;
- try{
- connection = DriverManager.getConnection(
- "jdbc:mysql://"+HOST+":"+PORT+"",
- USER_DB,
- PASS_DB
- );
- }
- catch (SQLException ex) {
- throw new RuntimeException("Connection not available.");
- }
- return connection;
- }
- public static void showSQLError(SQLException e, String query, int contesto) {
- String msg;
- if ((e.getErrorCode() == 17068 | e.getErrorCode() == 17011) &
- contesto == 0) {
- return; //questo errore non mi interessa
- }
- msg = "ErrorCode= " + e.getErrorCode() + "\n";
- msg += "Message= " + e.getMessage() + "\n";
- msg += "SQLState= " + e.getSQLState() + "\n";
- System.out.println(msg);
- }
- public static void showSQLError(SQLException e){
- showSQLError(e,"",0);
- }
- /*@Override
- public void attachView(View v) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement