Example usage for java.sql SQLException printStackTrace

List of usage examples for java.sql SQLException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:application.gen.gen.java

public static List<Table> getTablesName(String[] tableNames, Connection con) {
    List<Table> list = new ArrayList<Table>();

    try {// w  w w.  j  av a 2s  . c  om
        /*
         * ResultSet rs=con.getMetaData().getTables("ControlSystem", "dbo",
         * null, new String[]{"TABLE"}); while(rs!=null&&rs.next()) { //
         * System.out.println(rs.getString(3)); list.add(new
         * Table(rs.getString("TABLE_NAME"))); }
         */
        list.add(new Table("ProductBundleItems"));
        for (String tmp : tableNames) {
            Table table = new Table(tmp);
            table.setColumns(getColumns(con, null, null, tmp));
            list.add(table);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return list;
}

From source file:application.gen.gen.java

public static List<Table> getTablesName(List<String> tableNames, Connection con, String catalog, String schema,
        String dbType) {/*from  www . jav  a  2  s. com*/
    List<Table> list = new ArrayList<Table>();

    try {
        /*
         * ResultSet rs=con.getMetaData().getTables("ControlSystem", "dbo",
         * null, new String[]{"TABLE"}); while(rs!=null&&rs.next()) { //
         * System.out.println(rs.getString(3)); list.add(new
         * Table(rs.getString("TABLE_NAME"))); }
         */
        for (String tmp : tableNames) {
            Table table = new Table(tmp);
            table.setDbType(dbType);
            table.setColumns(getColumns(con, catalog, schema, tmp));
            list.add(table);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return list;
}

From source file:com.l2jfree.sql.L2DatabaseInstaller.java

private static void insertRevision(double revision) {
    System.out.println("Saving revision '" + revision + "'.");

    Connection con = null;/*  w w  w. j  a va2s .c  o  m*/
    try {
        con = L2Database.getConnection();

        PreparedStatement ps = con.prepareStatement("INSERT INTO _revision VALUES (?,?)");
        ps.setDouble(1, revision);
        ps.setLong(2, System.currentTimeMillis());
        ps.executeUpdate();
        ps.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        L2Database.close(con);
    }

    System.out.println("Done.");
}

From source file:com.l2jfree.sql.L2DatabaseInstaller.java

private static double getDatabaseRevision() {
    double revision = -1;

    Connection con = null;/*  w w w. j  a  v a  2 s  .  com*/
    try {
        con = L2Database.getConnection();

        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT revision FROM _revision ORDER BY revision DESC LIMIT 1");

        if (rs.next())
            revision = rs.getDouble(1);

        rs.close();
        st.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        L2Database.close(con);
    }

    return revision;
}

From source file:com.skilrock.lms.common.db.DBConnect.java

public static Connection getPropFileCon() {

    Connection connection = null;
    try {/*from   w w w .  j a  v a2 s  .c  om*/
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(url, userName, password);

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException se) {
        se.printStackTrace();
    }

    return connection;
}

From source file:common.DB.java

public static int update(String query) {
    try {/*from w ww.  jav  a  2 s  .  c  om*/
        DB.getConnection();
        if (resultSet != null) {
            resultSet.close();
            resultSet = null;
        }
        if (statement != null) {
            statement.close();
            statement = null;
        }
        statement = connection.createStatement();
        resultRow = statement.executeUpdate(query);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    close();
    return resultRow;
}

From source file:common.DB.java

public static ResultList query(String query) {
    ArrayList list = new ArrayList();
    ResultList result = new ResultList(list);
    try {//  w w  w.ja  v  a 2s . c om
        DB.getConnection();

        if (connection != null) {
            statement = connection.createStatement();
            resultSet = statement.executeQuery(query);
            ResultSetMetaData md = resultSet.getMetaData();
            int columns = md.getColumnCount();
            list.add(new HashMap(columns));
            while (resultSet.next()) {
                HashMap row = new HashMap(columns);
                for (int i = 1; i <= columns; ++i) {
                    row.put(md.getColumnLabel(i), resultSet.getString(i));
                }
                list.add(row);
            }
        } else {
            return null;
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    close();
    return result;
}

From source file:com.ibm.research.rdf.store.runtime.service.sql.UpdateHelper.java

private static String executeCall(Connection conn, String sql, int retPid, Object... params) {

    CallableStatement stmt = null;
    String ret = null;//from  w ww . j a  v a  2 s. c o  m

    try {
        conn.setAutoCommit(false);
    } catch (SQLException ex) {
        log.error(ex);
        ex.printStackTrace();
        System.out.println(ex.getLocalizedMessage());
        return ret;
    }

    try {

        stmt = conn.prepareCall(sql);
        int i = 1;
        for (Object o : params) {
            stmt.setObject(i, o);
            i++;
        }

        stmt.registerOutParameter(retPid, Types.VARCHAR);

        stmt.execute();
        ret = stmt.getString(retPid);

        conn.commit();

    } catch (SQLException e) {
        //         log.error(e);
        //         e.printStackTrace();
        //         System.out.println(e.getLocalizedMessage());
        ret = null;

        try {
            conn.rollback();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            log.error(e1);
            e1.printStackTrace();
            System.out.println(e1.getLocalizedMessage());
            ret = null;
        }

    } finally {
        closeSQLObjects(stmt, null);
    }

    try {
        conn.setAutoCommit(true);
    } catch (SQLException ex) {
        log.error(ex);
        ex.printStackTrace();
        System.out.println(ex.getLocalizedMessage());
        ret = null;
    }

    return ret;
}

From source file:common.DB.java

public static JSONArray createJson(String query, String label, String value) {
    //Get the formating of lable
    JSONArray jsonArray = new JSONArray();
    try {//w  w w  .  j  a v  a  2  s .  co  m
        DB.getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(query);
        rsmd = resultSet.getMetaData();
        int total_cols = resultSet.getMetaData().getColumnCount();
        while (resultSet.next()) {
            String toLabel = label;
            String toValue = value;
            JSONObject obj = new JSONObject();
            for (int i = 0; i < total_cols; i++) {
                String colName = rsmd.getColumnLabel(i + 1);
                toLabel = toLabel.replaceAll("\\[" + colName + "\\]", resultSet.getString(colName));
                toValue = toValue.replaceAll("\\[" + colName + "\\]", resultSet.getString(colName));
                obj.put(colName, resultSet.getObject(i + 1));
            }
            obj.put("label", toLabel);
            obj.put("value", toValue);
            jsonArray.put(obj);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    close();
    return jsonArray;
}

From source file:common.DB.java

public static JSONArray createJson(String query, String label, String value, String term) {
    //Get the formatting of label
    JSONArray jsonArray = new JSONArray();
    try {/*from  w  w  w  .j a v a  2s. c om*/
        DB.getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(query);
        rsmd = resultSet.getMetaData();
        int total_cols = resultSet.getMetaData().getColumnCount();
        while (resultSet.next()) {
            String toLabel = label;
            String toValue = value;
            JSONObject obj = new JSONObject();
            for (int i = 0; i < total_cols; i++) {
                String colName = rsmd.getColumnLabel(i + 1);
                toLabel = toLabel.replaceAll("\\[" + colName + "\\]", resultSet.getString(colName));
                toValue = toValue.replaceAll("\\[" + colName + "\\]", resultSet.getString(colName));
                obj.put(colName, resultSet.getObject(i + 1));
            }
            if (!(toLabel.toLowerCase()).contains(term.toLowerCase()))
                continue;
            obj.put("label", toLabel);
            obj.put("value", toValue);
            jsonArray.put(obj);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    close();
    return jsonArray;
}