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:i5.las2peer.services.todolist.Todolist.java

/**
 * // w  ww.  j av  a  2  s.com
 * createData
 * 
 * 
 * @return HttpResponse
 * 
 */
@POST
@Path("/data/{name}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "responseCreateData") })
@ApiOperation(value = "createData", notes = "")
public HttpResponse createData(@PathParam("name") String name) {
    Connection conn = null;
    try {

        conn = dbm.getConnection();
        PreparedStatement stmt = conn
                .prepareStatement("INSERT INTO gamificationCAE.todolist (name) VALUES (?)");
        stmt.setString(1, name);

        stmt.executeUpdate();

        return new HttpResponse(name + " is added!", HttpURLConnection.HTTP_OK);

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

        return new HttpResponse("Database connection error", HttpURLConnection.HTTP_INTERNAL_ERROR);
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.dialects.CreateTableStatement.java

public String getNativeSQL(Connection connection) {
    String createStatement = toSQLString();
    String query = null;/*w  w w.ja va2s. c o m*/
    try {
        query = connection.nativeSQL(createStatement);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (!createStatement.toString().equals(query)) {
        if (logger.isDebugEnabled())
            logger.debug("Original query : " + createStatement);
    }

    return query;
}

From source file:com.gatf.executor.dataprovider.SQLDatabaseTestDataSource.java

public void destroy() {
    for (Resource res : pool) {
        Connection conn = (Connection) res.object;
        try {/*from  w ww  . j a  v a  2s  . c  om*/
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    logger.info("Releasing connections....");
}

From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java

@Override
public boolean deleteAll() {
    boolean result = false;
    String sql = "delete from t_user;";

    try {//  w  w w .j  av a 2 s  .c  o  m
        Statement state = getConnection().createStatement();
        result = state.execute(sql);
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return result;
}

From source file:org.psystems.dicom.browser.server.stat.UseagStoreChartServlet.java

public JFreeChart getChart() {

    PreparedStatement psSelect = null;

    try {//ww  w.ja  va  2  s  .c o m

        Connection connection = Util.getConnection("main", getServletContext());
        long dcmSizes = 0;
        long imgSizes = 0;
        //
        // ALL_IMAGE_SIZE
        // ALL_DCM_SIZE

        // psSelect = connection
        // .prepareStatement("SELECT ID, METRIC_NAME, METRIC_DATE, METRIC_VALUE_LONG "
        // + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?");

        psSelect = connection.prepareStatement(
                "SELECT SUM(METRIC_VALUE_LONG) S " + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?");

        psSelect.setString(1, "ALL_DCM_SIZE");
        ResultSet rs = psSelect.executeQuery();
        while (rs.next()) {
            dcmSizes = rs.getLong("S");
        }
        rs.close();

        psSelect.setString(1, "ALL_IMAGE_SIZE");
        rs = psSelect.executeQuery();
        while (rs.next()) {
            imgSizes = rs.getLong("S");
        }
        rs.close();

        String dcmRootDir = getServletContext().getInitParameter("webdicom.dir.src");
        long totalSize = new File(dcmRootDir).getTotalSpace(); //TODO !
        long freeSize = new File(dcmRootDir).getFreeSpace();
        long busySize = totalSize - freeSize;

        //         System.out.println("!!! totalSize=" + totalSize + " freeSize="+freeSize);

        long diskEmpty = freeSize - imgSizes - dcmSizes;

        //         double KdiskEmpty = (double)diskEmpty/(double)totalSize;
        //         System.out.println("!!! " + KdiskEmpty);

        double KdiskBusi = (double) busySize / (double) totalSize * 100;
        //         System.out.println("!!! KdiskBusi=" + KdiskBusi);

        double KdcmSizes = (double) dcmSizes / (double) totalSize * 100;
        //         System.out.println("!!! KdcmSizes=" + KdcmSizes);

        double KimgSizes = (double) imgSizes / (double) totalSize * 100;
        //         System.out.println("!!! KimgSizes=" + KimgSizes);

        double KdiskFree = (double) freeSize / (double) (totalSize - KdcmSizes - KimgSizes) * 100;
        //         System.out.println("!!! KdiskFree=" + KdiskFree);

        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("??? (DCM-) " + dcmSizes / 1000 + " .", KdcmSizes);
        dataset.setValue("? (JPG-) " + imgSizes / 1000 + " .", KimgSizes);
        dataset.setValue("?  " + busySize / 1000 + " .", KdiskBusi);
        dataset.setValue(" " + freeSize / 1000 + " .", KdiskFree);

        boolean legend = true;
        boolean tooltips = false;
        boolean urls = false;

        JFreeChart chart = ChartFactory.createPieChart(
                "? ? ??  ?",
                dataset, legend, tooltips, urls);

        chart.setBorderPaint(Color.GREEN);
        chart.setBorderStroke(new BasicStroke(5.0f));
        // chart.setBorderVisible(true);
        // chart.setPadding(new RectangleInsets(20 ,20,20,20));

        return chart;

    } catch (SQLException e) {
        logger.error(e);
        e.printStackTrace();
    } finally {

        try {
            if (psSelect != null)
                psSelect.close();
        } catch (SQLException e) {
            logger.error(e);
        }
    }
    return null;

}

From source file:i5.las2peer.services.todolist.Todolist.java

/**
 * //  w ww  .j a  v a 2s . c  o m
 * getData
 * 
 * 
 * @return HttpResponse
 * 
 */
@GET
@Path("/data")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "responseGetData") })
@ApiOperation(value = "getData", notes = "")
public HttpResponse getData() {
    JSONObject dataJson = new JSONObject();
    Connection conn = null;
    try {

        conn = dbm.getConnection();
        PreparedStatement stmt = conn
                .prepareStatement("SELECT * FROM gamificationCAE.todolist ORDER BY id ASC");
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            dataJson.put(rs.getInt("id"), rs.getString("name"));

        }

        if (!dataJson.isEmpty()) {
            return new HttpResponse(dataJson.toJSONString(), HttpURLConnection.HTTP_OK);
        }
        return new HttpResponse("No data Found", HttpURLConnection.HTTP_OK);

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

        return new HttpResponse("Database connection error", HttpURLConnection.HTTP_INTERNAL_ERROR);
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:fr.calamus.common.db.core.DbPool.java

public int executeInTransaction(String sql, String key) {
    int n = -1;// w w w.  j  a  v a  2 s. c o  m
    try {
        log(sql);
        n = getStatement(key).executeUpdate(sql);
    } catch (SQLException e) {
        setLastExceptionMessage(e);
        e.printStackTrace();
    } finally {
        //closeStatement();
    }
    return n;
}

From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java

private long saveContact(Connection conn, Contact contact) {
    long id = -1;
    String sql = "insert into t_contact(f_email, f_phoneid, f_addressid)" + " values(?, ?, ?)";
    try {//from  w w  w.ja v a 2 s. c o  m
        PreparedStatement preState = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        preState.setString(1, contact.getEmail());
        preState.setLong(2, contact.getPhone().getId());
        preState.setLong(3, contact.getAddress().getId());
        preState.execute();
        id = generateId(preState);
        if (-1 != id) {
            contact.setId(id);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return id;
}

From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java

private long savePhone(Connection conn, Phone phone) {
    String sql = "insert into t_phone(f_number, f_phonetype) values(?, ?)";
    long id = -1;
    try {/*from   w  w w.j  ava 2s. co m*/
        // ?,?getGeneratedKeys
        PreparedStatement preState = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        preState.setString(1, phone.getNumber());
        preState.setInt(2, phone.getPhoneType());
        preState.execute();
        id = generateId(preState);
        if (-1 != id) {
            phone.setId(id);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return id;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.DeviceDAOImplTest.java

/**
 * Use the same deviceId but different appid
 *//*from w w  w  .  j  a  v a2  s  .  com*/
@Test
public void testAddDeviceWithDifferentAppId() throws DeviceNotFoundException {

    DeviceDAO dao = new DeviceDAOImpl(new BasicDataSourceConnectionProvider(ds));

    DevReg request = new DevReg();
    String deviceId = "433536df7038e1b7";
    request.setDevId(deviceId);
    request.setDisplayName("Rahul's android");
    request.setOsType(OSType.ANDROID.toString());
    request.setPushType(PushType.GCM.toString());
    request.setPushToken(
            "APA91bHaCculnOoolX0HV3f3CLHBY52C-H0lDS_m-lXXg5MbT9-EJiE6ooe0dUWURLuTQmVOttBS18cQwX5Pe-k9JDI2o8bq"
                    + "Rhi3UZ0McTNs9JADvguH63vihIbVAgAjUm4K8mOZcRG4MC-edQBiiZ87l-GnQKpZ4ejBRP3j72oVQI6ooDavac4");
    request.setOsVersion("macron");
    request.setVersionMajor(Constants.MMX_VERSION_MAJOR);
    request.setVersionMinor(Constants.MMX_VERSION_MINOR);
    String appId = "AAABSNIBKOstQST8";
    int id = dao.addDevice("login3", appId, request);
    assertTrue("Got a zero id", id > 0);
    try {
        DeviceEntity entity = dao.getDevice(appId, deviceId);
        assertNotNull(entity);
        DeviceEntity.Version version = entity.getProtocolVersion();
        DeviceEntity.Version expected = new DeviceEntity.Version(Constants.MMX_VERSION_MAJOR,
                Constants.MMX_VERSION_MINOR);
        assertEquals("Non matching version", expected, version);
    } catch (SQLException e) {
        e.printStackTrace();
        fail("testAddDeviceWithDifferentAppId failed");
    }

}