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:com.ibm.research.rdf.store.jena.impl.DB2ResultSetImpl.java

public DB2ResultSetImpl(LiteralInfoResultSet rs, Store store, Connection c, List<String> list,
        VarExprList varExprList) {/*from   ww w  . j  ava  2 s . c  o m*/
    liRs = rs;
    set = rs.getResultSet();
    try {
        ResultSetMetaData rsMetaData = set.getMetaData();
        int numberOfColumns = rsMetaData.getColumnCount();

        // get the column names; column indexes start from 1
        for (int i = 1; i <= numberOfColumns; i++) {
            columnNames.add(rsMetaData.getColumnName(i));

        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException("Error getting result metadata");
    }
    this.store = store;
    connection = c;

    if (varExprList.isEmpty()) {
        varList = list;
    } else {
        List<Var> vars = varExprList.getVars();
        varList = new ArrayList<String>();
        for (int i = 0; i < vars.size(); i++) {
            varList.add(vars.get(i).getName());
        }
    }
}

From source file:com.jjtree.servelet.Paragraphs.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from w ww .j  a  v  a 2  s . c om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);

    String pathInfo = request.getPathInfo();
    String[] path = pathInfo.split("/");
    int singleParagraphID = Integer.parseInt(path[1]);

    try {
        // Register JDBC driver
        Class.forName(JConstant.JDBC_DRIVER);

        // Open a connection
        conn = DriverManager.getConnection(JConstant.DB_URL, JConstant.USER, JConstant.PASSWORD);

        // Execute SQL query
        stmt = conn.createStatement();
        String sql;
        sql = "SELECT * FROM JParagraph WHERE paragraphID = " + singleParagraphID;
        ResultSet rs = stmt.executeQuery(sql);

        // Extract data from result set
        while (rs.next()) {
            //Retrieve by column name
            int paragraphID = rs.getInt("paragraphID");
            int articleID = rs.getInt("articleID");
            int position = rs.getInt("position");

            String type = rs.getString("type");
            String content = rs.getString("content");

            JSONObject paragraph = new JSONObject();

            paragraph.put("paragraphID", paragraphID);
            paragraph.put("articleID", articleID);
            paragraph.put("position", position);

            paragraph.put("type", type);
            paragraph.put("content", content);

            PrintWriter writer = response.getWriter();
            writer.print(paragraph);
            writer.flush();
        }

        // Clean-up environment
        rs.close();
        stmt.close();
        conn.close();
    } catch (SQLException se) {
        //Handle errors for JDBC
        se.printStackTrace();
    } catch (Exception e) {
        //Handle errors for Class.forName
        e.printStackTrace();
    } finally {
        //finally block used to close resources
        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException se2) {
        } // nothing we can do
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException se) {
            se.printStackTrace();
        } //end finally try
    } //end try
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getUsagePerClient(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 *//*from  ww  w  .ja  v a2s.  co m*/
@Override
public UsagePerClientBean getUsagePerClient(String organizationId, String apiId, String version, DateTime from,
        DateTime to) {
    try {
        QueryRunner run = new QueryRunner(ds);
        String sql = "SELECT client_id, count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY client_id"; //$NON-NLS-1$
        ResultSetHandler<UsagePerClientBean> handler = new UsagePerClientHandler();
        return run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
        return new UsagePerClientBean();
    }
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getUsagePerPlan(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 *//*w  ww . j av  a 2 s . c o m*/
@Override
public UsagePerPlanBean getUsagePerPlan(String organizationId, String apiId, String version, DateTime from,
        DateTime to) {
    try {
        QueryRunner run = new QueryRunner(ds);
        String sql = "SELECT plan, count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY plan"; //$NON-NLS-1$
        ResultSetHandler<UsagePerPlanBean> handler = new UsagePerPlanHandler();
        return run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
        return new UsagePerPlanBean();
    }
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStatsSummary(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 *///from  w  w w.j a v a  2  s  . co m
@Override
public ResponseStatsSummaryBean getResponseStatsSummary(String organizationId, String apiId, String version,
        DateTime from, DateTime to) {
    try {
        QueryRunner run = new QueryRunner(ds);
        String sql = "SELECT resp_type, count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY resp_type"; //$NON-NLS-1$
        ResultSetHandler<ResponseStatsSummaryBean> handler = new ResponseStatsSummaryHandler();
        return run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
        return new ResponseStatsSummaryBean();
    }
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStatsPerClient(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 *///from   ww w .  j  a v  a  2 s.  c  o  m
@Override
public ResponseStatsPerClientBean getResponseStatsPerClient(String organizationId, String apiId, String version,
        DateTime from, DateTime to) {
    try {
        QueryRunner run = new QueryRunner(ds);
        String sql = "SELECT client_id, resp_type, count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY client_id, resp_type"; //$NON-NLS-1$
        ResultSetHandler<ResponseStatsPerClientBean> handler = new ResponseStatsPerClientHandler();
        return run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
        return new ResponseStatsPerClientBean();
    }
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStatsPerPlan(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 *///ww  w. j  a va2s  .  c  om
@Override
public ResponseStatsPerPlanBean getResponseStatsPerPlan(String organizationId, String apiId, String version,
        DateTime from, DateTime to) {
    try {
        QueryRunner run = new QueryRunner(ds);
        String sql = "SELECT plan, resp_type, count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY plan, resp_type"; //$NON-NLS-1$
        ResultSetHandler<ResponseStatsPerPlanBean> handler = new ResponseStatsPerPlanHandler();
        return run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
        return new ResponseStatsPerPlanBean();
    }
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getClientUsagePerApi(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 *///from  ww w . jav a 2 s .  c  o m
@Override
public ClientUsagePerApiBean getClientUsagePerApi(String organizationId, String clientId, String version,
        DateTime from, DateTime to) {
    try {
        QueryRunner run = new QueryRunner(ds);
        String sql = "SELECT api_id, count(*) FROM gw_requests WHERE client_org_id = ? AND client_id = ? AND client_version = ? AND rstart >= ? AND rstart < ? GROUP BY api_id"; //$NON-NLS-1$
        ResultSetHandler<ClientUsagePerApiBean> handler = new ClientUsagePerApiHandler();
        return run.query(sql, handler, organizationId, clientId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
        return new ClientUsagePerApiBean();
    }
}

From source file:edu.asu.msse.sgowdru.moviesqldb.SearchMovie.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_movie);
    info = new TextView[5];
    //In the info array of TextView type store id of each field
    info[0] = (TextView) findViewById(R.id.autoCompleteTextView);
    info[1] = (TextView) findViewById(R.id.editTitleSearch);
    info[2] = (TextView) findViewById(R.id.editGenreSearch);
    info[3] = (TextView) findViewById(R.id.editYearSearch);
    info[4] = (TextView) findViewById(R.id.editActorsSearch);

    //Ratings field is of type Spinner class with field values (PG, PG-13, R rated)
    dropdown = (Spinner) findViewById(R.id.spinnerSearch);
    adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dropdown.setAdapter(adapter);/*  ww  w  .j a v a  2 s  .co  m*/

    btn = (Button) findViewById(R.id.addSearch);

    context = getApplicationContext();
    duration = Toast.LENGTH_LONG;

    db = new MoviesDB(this);
    try {
        crsDB = db.openDB();
    } catch (SQLException e) {
        e.printStackTrace();
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            gen);
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.editGenreSearch);
    textView.setAdapter(adapter);
}

From source file:edu.byu.wso2.apim.extensions.BYUIdentifiersLookup.java

public boolean mediate(MessageContext synapseContext) {
    SynapseLog synLog = getLog(synapseContext);

    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Start : BYUIdentifiersLookup mediator");
        if (synLog.isTraceTraceEnabled()) {
            synLog.traceTrace("Message : " + synapseContext.getEnvelope());
        }//from  w  w w  .j  a v  a  2  s .  c  o  m
    }

    Connection con = null;
    PreparedStatement statement = null;
    ResultSet resultSet = null;

    String identifier = (String) synapseContext.getProperty(netIdPropertyToUse);

    String idType = "net_id";

    if (identifier.contains("=")) {
        String[] idPieces = identifier.split("=");
        idType = idPieces[0];
        identifier = idPieces[1];
    }

    String query;
    switch (idType) {
    case "byu_id":
        query = "select net_id, byu_id, person_id from pro.person where byu_id = ?";
        break;
    case "person_id":
        query = "select net_id, byu_id, person_id from pro.person where person_id = ?";
        break;
    case "net_id":
        query = "select net_id, byu_id, person_id from pro.person where net_id = ?";
        break;
    default:
        synLog.error("Unidentified identifier type (" + idType + ")");
        return false;
    }

    if (synLog.isTraceOrDebugEnabled())
        log.debug("BYUIdentifiersLookup: lookup starting for identifier:" + identifier + " type:" + idType);

    try {
        con = ds.getConnection();
        if (synLog.isTraceOrDebugEnabled())
            synLog.traceOrDebug("connection acquired. creating statement and executing query");
        statement = con.prepareStatement(query);
        statement.setString(1, identifier);
        resultSet = statement.executeQuery();
        if (resultSet.next()) {
            String net_id = resultSet.getString("net_id");
            String byu_id = resultSet.getString("byu_id");
            String person_id = resultSet.getString("person_id");
            if (synLog.isTraceOrDebugEnabled())
                synLog.traceOrDebug("BYUId is " + byu_id + " PersonId is " + person_id);
            synapseContext.setProperty(propertyPrefix + "NetId", net_id);
            synapseContext.setProperty(propertyPrefix + "BYUId", byu_id);
            synapseContext.setProperty(propertyPrefix + "PersonId", person_id);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
    }
    if (log.isDebugEnabled())
        log.debug("BYUIdentifiersLookup: ending");
    return true;
}