Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean connect()
- {
- try
- {
- Class.forName(DRIVER).newInstance();
- con=DriverManager.getConnection(URL, LOGIN, PASSWORD);
- }
- catch(ClassNotFoundException ex){
- //System.out.print("Error " + ex.getMessage());
- JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
- return false;
- }catch(IllegalAccessException ex){
- //System.out.print("Error " + ex.getMessage());
- JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
- return false;
- }catch(InstantiationException ex){
- //System.out.print("Error " + ex.getMessage());
- JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
- return false;
- }catch(SQLException ex){
- //System.out.print("Error " + ex.getMessage());
- JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
- return false;
- }
- return true;
- }
- //Мой вариант
- /**
- * Установка соединения с БД.
- */
- public void init(){
- try {
- //settings.getDriverclass() - это com.mysql.jdbc.Driver
- Class.forName(settings.getDriverclass());
- String url = String.format("jdbc:%s://%s:%d/%s", settings.getDriver(), settings.getHost(), settings.getPort(), settings.getScheme());
- LOG.log(Level.SEVERE, url);
- //оно из настроек логин тащит
- String login = settings.getLogin();
- //пароль тащит
- String password = settings.getPassword();
- con = DriverManager.getConnection(url, login, password);
- } catch (SQLException ex) {
- LOG.log(Level.SEVERE, "Connenction failed", ex);
- } catch (ClassNotFoundException ex) {
- LOG.log(Level.SEVERE, String.format("DriverClass %s not found", settings.getDriverclass()), ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement