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:json.JobController.java

@RequestMapping(value = "/getSingleJob", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody Jobs getSingleJob(@RequestBody Jobs job) {
    Connection conn = null;//from  w  ww.  j  av  a 2  s  . c o  m
    PreparedStatement stmt = null;
    ResultSet rs = null;
    Jobs j = null;
    String query = "select * from job where jobID = ?";

    try {
        //Set up connection with database
        conn = ConnectionManager.getConnection();
        stmt = conn.prepareStatement(query);

        //set username
        //stmt.setString(1, Integer.parseInt(job.getJobId()));
        stmt.setInt(1, job.getJobId());

        //Execute sql satatement to obtain account from database
        rs = stmt.executeQuery();
        //     System.out.println("jobid" + query)
        while (rs != null && rs.next()) {
            int jobID = rs.getInt(1);
            String postingTitle = rs.getString(2);
            String businessUnit = rs.getString(3);
            String location = rs.getString(4);
            String createdBy = rs.getString(5);
            String createdOn = rs.getString(6);
            String employmentType = rs.getString(8);
            String shift = rs.getString(9);
            String description = rs.getString(10);
            String requirement = rs.getString(11);
            String validity = rs.getString(12);

            j = new Jobs(jobID, businessUnit, postingTitle, createdBy, createdOn, location, employmentType,
                    shift, description, requirement, validity);

        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        ConnectionManager.close(conn, stmt, rs);
    }

    return j;
}

From source file:com.jaspersoft.hadoop.hive.jasperserver.HiveDataSourceService.java

@Override
public boolean testConnection() throws JRException {
    try {/*from  w w  w  .j  av  a2 s .com*/
        createConnection();
        if (connection == null) {
            return false;
        }
        connection.test();
        return true;
    } catch (SQLException e) {
        e.printStackTrace();
        return false;
    } finally {
        closeConnection();
    }
}

From source file:com.jp.systemdirector.projectzero.zab01.ap.logicbean.SZAB0111SelectLogicBean.java

@Transactional
public SZAB0111SelectResultData getUserById(ContextData context, SZAB0111SelectInputData inputData) {

    // ????List/*from w  w w .j  av a  2 s  .  c  o m*/
    List<SZAB0111SelectDTO> resultList = new ArrayList<SZAB0111SelectDTO>();

    if (context != null) {
        SZAB0111SelectDTO zDto = new SZAB0111SelectDTO();
        zDto.setUserid(context.getUserid());

        // 
        try {

            resultList = dao.findById(zDto);
        } catch (SQLException e) {

            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    // DTO?ContextData????PR???
    List<ContextData> contextDataList = new ArrayList<ContextData>();
    for (SZAB0111SelectDTO zSelectDTO : resultList) {
        if (zSelectDTO == null) {
            break;
        }

        ContextData contextData = new ContextData();

        try {
            contextData.setUserid(zSelectDTO.getUserid());
            contextData.setUsername(zSelectDTO.getUsername());
            contextData.setPassword(zSelectDTO.getPassword());

            contextDataList.add(contextData);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    // ?ListMemberResultData?memberList??
    SZAB0111SelectResultData resultData = new SZAB0111SelectResultData();
    resultData.setResultList(contextDataList);

    return resultData;
}

From source file:com.orientechnologies.orient.jdbc.spring.IoTatWorkThread.java

public void run() {
    try {/*w  w  w.jav a  2s  . c o  m*/
        PreparedStatement queryPrepStatement = connection
                .prepareStatement("SELECT FROM OGraphVertex WHERE name = ?");
        queryPrepStatement.setString(1, ROOT_VERTEX_NAME);
        ResultSet rs = queryPrepStatement.executeQuery();

        Assert.assertTrue(NAME + "There is no vertex with name " + ROOT_VERTEX_NAME, rs.first());
        //the RID is always the first element in the RS
        Object vertexId = rs.getObject(1);
        OrientGraph g = connection.unwrap(OrientGraph.class);
        Vertex v = g.getVertex(vertexId);

        Iterator<Edge> categories = v.getEdges(Direction.OUT, "category").iterator();
        Edge categoryEdge;
        Vertex aggregationV = null;
        while (categories.hasNext() && aggregationV == null) {
            categoryEdge = categories.next();
            if (categoryEdge.getVertex(Direction.IN).getProperty("name").equals("Aggregation"))
                aggregationV = categoryEdge.getVertex(Direction.IN);
        }
        Assert.assertNotNull("Missing aggregation category", aggregationV);
        Iterator<Edge> containmentRels = aggregationV.getEdges(Direction.OUT, CONTAINMENT_RELATION_EDGE)
                .iterator();
        Assert.assertTrue(NAME + "There is no edge with label '" + CONTAINMENT_RELATION_EDGE + "' coming from "
                + v.toString(), containmentRels.hasNext());

        String prefix = NAME + "Values:: ";
        StringBuilder textToBePrinted = new StringBuilder(prefix);
        Edge currentRel;
        while (containmentRels.hasNext()) {
            currentRel = containmentRels.next();
            if (textToBePrinted.length() == prefix.length())
                textToBePrinted.append(currentRel.getVertex(Direction.IN).getProperty("name").toString());
            else
                textToBePrinted
                        .append(", " + currentRel.getVertex(Direction.IN).getProperty("name").toString());
        }
        System.out.println(textToBePrinted);
    } catch (SQLException e) {
        e.printStackTrace();
        Assert.fail();
    }

}

From source file:com.persistent.cloudninja.dao.impl.PartitionStatsAndBWUsageDaoImpl.java

/**
 * Get the database bandwidth usage for databases other than master.
 * It includes the Egress and Ingress kilobytes.
 *//*from www.  ja v  a 2s  . c o m*/
@Override
public List<DBBandwidthUsageEntity> getBandwidthUsage() {
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    List<DBBandwidthUsageEntity> listBWUsageEntity = null;
    try {
        connection = provisionConnectionUtility.getConnection(url, MASTER_DB, MASTER_DB_USER, MASTER_DB_PSWD);
        preparedStatement = connection
                .prepareStatement("SELECT convert(varchar(8),sys.bandwidth_usage.time, 1) "
                        + "as usage_day, database_name, direction, sum(quantity) as kiloBytes "
                        + "FROM sys.bandwidth_usage where class = 'Internal' and database_name <> '" + MASTER_DB
                        + "' "
                        + "and convert(varchar(8),sys.bandwidth_usage.time, 1) = convert(varchar(8),getutcdate(), 1) "
                        + "group by convert(varchar(8),sys.bandwidth_usage.time, 1), database_name, direction "
                        + "order by convert(varchar(8),sys.bandwidth_usage.time, 1), database_name, direction");
        ResultSet resultSet = preparedStatement.executeQuery();
        DBBandwidthUsageEntity dbBandwidthUsageEntity = null;
        listBWUsageEntity = new ArrayList<DBBandwidthUsageEntity>();
        while (resultSet.next()) {
            dbBandwidthUsageEntity = new DBBandwidthUsageEntity();
            dbBandwidthUsageEntity.setUsageDay(resultSet.getString(1));
            dbBandwidthUsageEntity.setDatabaseName(resultSet.getString(2));
            dbBandwidthUsageEntity
                    .setDirection(BandwidthUsageDirection.valueOf(resultSet.getString(3).toUpperCase()));
            dbBandwidthUsageEntity.setKiloBytes(resultSet.getLong(4));

            listBWUsageEntity.add(dbBandwidthUsageEntity);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        provisionConnectionUtility.closeStatement(preparedStatement);
        provisionConnectionUtility.closeConnection(connection);
    }
    return listBWUsageEntity;
}

From source file:io.kahu.hawaii.util.call.sql.AbortableQuery.java

@Override
protected void abortInternally() {
    try {
        aborted = true;
        preparedStatement.cancel();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:gsn.vsensor.TestStreamExporterVirtualSensor.java

public void tearDown() {
    config = null;//from   www  .ja  va2 s  .  c  o  m
    try {
        DriverManager.registerDriver(new org.h2.Driver());
        Connection connection = DriverManager.getConnection(url, user, passwd);
        connection.createStatement().execute("DROP TABLE IF EXISTS " + streamName);
    } catch (SQLException e) {
        e.printStackTrace();
    }

}

From source file:com.abixen.platform.service.businessintelligence.multivisualization.service.impl.JsonFilterServiceImpl.java

private Map<String, String> getColumnTypeMapping(ResultSetMetaData rsmd) throws SQLException {
    int columnCount = rsmd.getColumnCount();
    Map<String, String> columnTypeMapping = new HashMap<>();

    IntStream.range(1, columnCount + 1).forEach(i -> {
        try {//w  w w  .  j  a v  a 2  s .  co  m
            String columnTypeName = rsmd.getColumnTypeName(i);
            if ("BIGINT".equals(columnTypeName)) {
                columnTypeName = "INTEGER";
            }
            if ("VARCHAR".equals(columnTypeName)) {
                columnTypeName = "STRING";
            }
            if ("FLOAT8".equals(columnTypeName)) {
                columnTypeName = "DOUBLE";
            }
            columnTypeMapping.put(rsmd.getColumnName(i).toUpperCase(), columnTypeName.toUpperCase());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
    return columnTypeMapping;
}

From source file:fr.eurecom.nerd.api.rest.Document.java

@POST
@RolesAllowed({ "user" })
@Produces(MediaType.APPLICATION_JSON)//from   w w  w.ja v  a 2  s.  c  o  m
public Response doPostJSON(@Context UriInfo ui, @Context SecurityContext context,
        @FormParam("text") String text, @FormParam("timedtext") String timedtext,
        @FormParam("uri") String uri) {
    NerdPrincipal user = ((NerdPrincipal) context.getUserPrincipal());

    ResponseBuilder response = null;
    JSONObject jo = new JSONObject();

    try {
        LogFactory.logger.info("user:" + user.getId() + " requires to store a resource");

        if (text == null && timedtext == null && uri == null)
            return Response.status(Status.NOT_ACCEPTABLE).header("Access-Control-Allow-Origin", "*")
                    .entity("Wrong parameters").build();

        TDocument document = new TDocument(text, timedtext, uri);
        int idDocument = sql.selectDocument(document);
        if (idDocument != -1)
            response = Response.status(Status.OK);
        else {
            idDocument = sql.insertDocument(document);
            //201 OK resource created
            String resource = ui.getAbsolutePath().toString();
            response = Response.created(new URI(resource + "/" + idDocument));
        }
        jo.put("idDocument", idDocument);
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (LanguageException e) {
        return Response.status(Status.NOT_ACCEPTABLE).header("Access-Control-Allow-Origin", "*")
                .entity(e.getMessage()).build();
    }

    return response.header("Access-Control-Allow-Origin", "*").entity(jo.toString() + "\n").build();
}

From source file:database.DataBaseMySQL.java

public int getRowCount(ResultSet resultSet) {
    if (resultSet == null) {
        return 0;
    }// w  w  w  .  j  a v a  2  s .c om
    try {
        resultSet.last();
        return resultSet.getRow();
    } catch (SQLException exp) {
        exp.printStackTrace();
    } finally {
        try {
            resultSet.beforeFirst();
        } catch (SQLException exp) {
            exp.printStackTrace();
        }
    }
    return 0;
}