Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

In this page you can find the example usage for java.sql SQLException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.dspace.administer.CommunityFiliator.java

public static void main(String[] argv) throws Exception {
    // create an options object and populate it
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    options.addOption("s", "set", false, "set a parent/child relationship");
    options.addOption("r", "remove", false, "remove a parent/child relationship");
    options.addOption("p", "parent", true, "parent community (handle or database ID)");
    options.addOption("c", "child", true, "child community (handle or databaseID)");
    options.addOption("h", "help", false, "help");

    CommandLine line = parser.parse(options, argv);

    String command = null; // set or remove
    String parentID = null;//from  ww  w.ja  v a  2  s. c o  m
    String childID = null;

    if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("CommunityFiliator\n", options);
        System.out.println("\nestablish a relationship: CommunityFiliator -s -p parentID -c childID");
        System.out.println("remove a relationship: CommunityFiliator -r -p parentID -c childID");

        System.exit(0);
    }

    if (line.hasOption('s')) {
        command = "set";
    }

    if (line.hasOption('r')) {
        command = "remove";
    }

    if (line.hasOption('p')) // parent
    {
        parentID = line.getOptionValue('p');
    }

    if (line.hasOption('c')) // child
    {
        childID = line.getOptionValue('c');
    }

    // now validate
    // must have a command set
    if (command == null) {
        System.out.println("Error - must run with either set or remove (run with -h flag for details)");
        System.exit(1);
    }

    if ("set".equals(command) || "remove".equals(command)) {
        if (parentID == null) {
            System.out.println("Error - a parentID must be specified (run with -h flag for details)");
            System.exit(1);
        }

        if (childID == null) {
            System.out.println("Error - a childID must be specified (run with -h flag for details)");
            System.exit(1);
        }
    }

    CommunityFiliator filiator = new CommunityFiliator();
    Context c = new Context();

    // ve are superuser!
    c.setIgnoreAuthorization(true);

    try {
        // validate and resolve the parent and child IDs into commmunities
        Community parent = filiator.resolveCommunity(c, parentID);
        Community child = filiator.resolveCommunity(c, childID);

        if (parent == null) {
            System.out.println("Error, parent community cannot be found: " + parentID);
            System.exit(1);
        }

        if (child == null) {
            System.out.println("Error, child community cannot be found: " + childID);
            System.exit(1);
        }

        if ("set".equals(command)) {
            filiator.filiate(c, parent, child);
        } else {
            filiator.defiliate(c, parent, child);
        }
    } catch (SQLException sqlE) {
        System.out.println("Error - SQL exception: " + sqlE.toString());
    } catch (AuthorizeException authE) {
        System.out.println("Error - Authorize exception: " + authE.toString());
    } catch (IOException ioE) {
        System.out.println("Error - IO exception: " + ioE.toString());
    }
}

From source file:classes.connectionPool.java

public static Connection getConexion() {
    Connection con = null;/*from w w  w  .  j  a  v  a  2 s .com*/
    try {
        con = dataSource.getConnection();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
    return con;
}

From source file:classes.connectionPool.java

public static void connectionRelease(Connection conexion) {
    try {//from   w  w w .  j a  v  a2 s.c om
        if (null != conexion)
            // En realidad no cierra, solo libera la conexion.
            conexion.close();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:framework.classes.PoolConexion.java

/**
 * OPEN CONNECTION/*from   w  ww .j a  v  a2 s . co m*/
 * @return 
 */
public static Connection OcuparConexion() {
    Connection conexion = null;
    try {
        conexion = dataSource.getConnection();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
    return conexion;
}

From source file:framework.classes.PoolConexion.java

/**
 * CLOSE CONNECTION//from w  w  w  .j  ava 2  s.  c  o  m
 * @param conexion 
 */
public static void LiberarConexion(Connection conexion) {
    try {
        if (null != conexion)
            // En realidad no cierra, solo libera la conexion.
            conexion.close();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:framework.clss.ConnectionBD.java

public static void liberaConexion(Connection conexion) {
    try {/*from   w w  w . jav  a2s .c o m*/
        if (null != conexion)
            conexion.close();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:App.classes.BD_Connection.java

public static Connection getConection() {
    Connection conexion = null;/* w  w  w  . j  a  va  2 s .c om*/
    try {
        conexion = Singleton_App.dataSource.getConnection();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
    return conexion;
}

From source file:App.classes.BD_Connection.java

public static void liberateConection(Connection conection) {
    try {/*w  w w.ja va 2s  .c  o  m*/
        if (null != conection) // En realidad no cierra, solo libera la conexion.
        {
            conection.close();
        }
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:Classes.DBConnection.java

/**
 * Used to release connection/*w w w  .  j a  va 2 s . c  om*/
 * @param connection is the connection to release
 */
public static void releaseConnection(Connection connection) {
    try {
        if (null != connection)
            // En realidad no cierra, solo libera la conexion.
            connection.close();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:application.bbdd.pool.java

public static Connection getConexion() {
    Connection conexion = null;//from   www  . ja va  2s.  c o m
    try {
        conexion = dataSource.getConnection();
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
    return conexion;
}