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:nu.kelvin.jfileshare.servlets.AboutServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServletContext app = getServletContext();
    RequestDispatcher disp;//from ww  w.  j a  va  2s .c  o  m
    req.setAttribute("tab", "About");
    disp = app.getRequestDispatcher("/templates/About.jsp");
    HttpSession session = req.getSession();
    Conf conf = (Conf) app.getAttribute("conf");

    req.setAttribute("daysLogRetention", conf.getDaysLogRetention());

    if (session.getAttribute("user") != null) {
        Connection dbConn = null;
        PreparedStatement st = null;
        try {
            long bytesStoreAvailable = FileSystemUtils.freeSpaceKb(conf.getPathStore()) * 1024;
            req.setAttribute("bytesStoreAvailable", FileItem.humanReadable(bytesStoreAvailable));

            dbConn = ds.getConnection();
            st = dbConn.prepareStatement(
                    "select cast(count(1) as char) as logins, cast(count(distinct payload) as char) as uniqueLogins from Logs where action=\"login\" and date > (now() - INTERVAL ? DAY)");
            st.setInt(1, conf.getDaysLogRetention());
            ResultSet rs = st.executeQuery();
            if (rs.first()) {
                req.setAttribute("logins", rs.getString("logins"));
                req.setAttribute("uniqueLogins", rs.getString("uniqueLogins"));
            }

            st = dbConn.prepareStatement(
                    "select cast(count(1) as char) as downloads, sum(cast(payload as unsigned)) as bytesDownloads from Logs where action=\"download\" and date > (now() - INTERVAL ? DAY)");
            st.setInt(1, conf.getDaysLogRetention());
            rs = st.executeQuery();
            if (rs.first()) {
                req.setAttribute("downloads", rs.getString("downloads"));
                req.setAttribute("bytesDownloads", FileItem.humanReadable(rs.getLong("bytesDownloads")));
            }

            st = dbConn.prepareStatement(
                    "select cast(count(1) as char) as uploads, sum(cast(payload as unsigned)) as bytesUploads from Logs where action=\"upload\" and date > (now() - INTERVAL ? DAY)");
            st.setInt(1, conf.getDaysLogRetention());
            rs = st.executeQuery();
            if (rs.first()) {
                req.setAttribute("uploads", rs.getString("uploads"));
                req.setAttribute("bytesUploads", FileItem.humanReadable(rs.getLong("bytesUploads")));
            }
            st.close();
        } catch (SQLException e) {
            logger.severe(e.toString());
        } finally {
            if (dbConn != null) {
                try {
                    dbConn.close();
                } catch (SQLException ignore) {
                }
            }
        }
    }
    disp.forward(req, resp);
}

From source file:org.apache.sqoop.manager.TestMainframeManager.java

@Test
public void testGetConnection() {
    try {/*from  w ww  .ja  v  a 2 s. c  o  m*/
        Connection con = manager.getConnection();
        assertNull("manager should not return a connection", con);
    } catch (SQLException sqlE) {
        fail("Got SQLException: " + sqlE.toString());
    }
}

From source file:org.apache.sqoop.manager.TestMainframeManager.java

@Test
public void testReadTable() {
    String[] colNames = manager.getColumnNames(getTableName());
    try {/*  w  ww.  j a  v  a 2s .  c o  m*/
        ResultSet table = manager.readTable(getTableName(), colNames);
        assertNull("manager should not read a table", table);
    } catch (SQLException sqlE) {
        fail("Got SQLException: " + sqlE.toString());
    }
}

From source file:fi.helsinki.lib.simplerest.CommunityLogoResource.java

@Get
public Representation get() {
    Context c = null;//w ww .  j  av  a2  s. c  o m
    Community community;
    try {
        c = new Context();
        community = Community.find(c, this.communityId);
        if (community == null) {
            return errorNotFound(c, "Could not find the community.");
        }
    } catch (SQLException e) {
        return errorInternal(c, e.toString());
    }

    InputStream inputStream = null;
    Bitstream logo = null;
    try {
        logo = community.getLogo();
        if (logo == null) {
            return errorNotFound(c, "The community has no logo.");
        }
        inputStream = logo.retrieve();
    } catch (Exception e) {
        return errorInternal(c, e.toString());
    }

    MediaType mediaType = MediaType.valueOf(logo.getFormat().getMIMEType());
    c.abort();
    return new BinaryRepresentation(mediaType, inputStream);
}

From source file:fi.helsinki.lib.simplerest.CollectionLogoResource.java

@Put
public Representation put(Representation logoRepresentation) {
    Context c = null;//from   w w  w. j  av a2s . c o  m
    Collection collection;
    try {
        c = getAuthenticatedContext();
        collection = Collection.find(c, this.collectionId);
        if (collection == null) {
            return errorNotFound(c, "Could not find the collection.");
        }
    } catch (SQLException e) {
        return errorInternal(c, e.toString());
    }

    try {
        RestletFileUpload rfu = new RestletFileUpload(new DiskFileItemFactory());
        FileItemIterator iter = rfu.getItemIterator(logoRepresentation);
        if (iter.hasNext()) {
            FileItemStream item = iter.next();
            if (!item.isFormField()) {
                InputStream inputStream = item.openStream();

                collection.setLogo(inputStream);
                Bitstream logo = collection.getLogo();
                BitstreamFormat bf = BitstreamFormat.findByMIMEType(c, item.getContentType());
                logo.setFormat(bf);
                logo.update();
                collection.update();
            }
        }
        c.complete();
    } catch (AuthorizeException ae) {
        return error(c, "Unauthorized", Status.CLIENT_ERROR_UNAUTHORIZED);
    } catch (Exception e) {
        return errorInternal(c, e.toString());
    }

    return successOk("Logo set.");
}

From source file:fi.helsinki.lib.simplerest.CommunityLogoResource.java

@Put
public Representation put(Representation logoRepresentation) {
    Context c = null;//from w  w w. j  av a  2s  . com
    Community community;
    try {
        c = getAuthenticatedContext();
        community = Community.find(c, this.communityId);
        if (community == null) {
            return errorNotFound(c, "Could not find the community.");
        }
    } catch (SQLException e) {
        return errorInternal(c, e.toString());
    }

    try {
        RestletFileUpload rfu = new RestletFileUpload(new DiskFileItemFactory());
        FileItemIterator iter = rfu.getItemIterator(logoRepresentation);
        if (iter.hasNext()) {
            FileItemStream item = iter.next();
            if (!item.isFormField()) {
                InputStream inputStream = item.openStream();

                community.setLogo(inputStream);
                Bitstream logo = community.getLogo();
                BitstreamFormat bf = BitstreamFormat.findByMIMEType(c, item.getContentType());
                logo.setFormat(bf);
                logo.update();
                community.update();
            }
        }
        c.complete();
    } catch (AuthorizeException ae) {
        return error(c, "Unauthorized", Status.CLIENT_ERROR_UNAUTHORIZED);
    } catch (Exception e) {
        return errorInternal(c, e.toString());
    }

    return successOk("Logo set.");
}

From source file:org.apache.sqoop.TestAutoResetMapper.java

@Before
public void setUp() {
    // start the server
    super.setUp();

    if (useHsqldbTestServer()) {
        // throw away TWOINTTABLE and things we don't care about.
        try {/*from  w  w  w. j  av  a 2 s  .  c o m*/
            this.getTestServer().dropExistingSchema();
        } catch (SQLException sqlE) {
            fail(sqlE.toString());
        }
    }

    this.tableNames = new ArrayList<String>();

    int numTables = types.length;

    this.expectedStrings = new String[numTables][];

    int numRows = 2;

    for (int i = 0; i < numTables; ++i) {
        expectedStrings[i] = new String[numRows];
        List<String> vals = new ArrayList<String>();
        for (int j = 0; j < numRows; ++j) {
            String num = Integer.toString(j + 1);
            String str = "Table " + Integer.toString(i + 1) + " Row " + num;
            vals.add(num);
            vals.add("'" + str + "'");
            expectedStrings[i][j] = num + "," + str;
        }
        this.createTableWithColTypes(types[i], vals.toArray(new String[vals.size()]));
        this.tableNames.add(this.getTableName());
        this.removeTableDir();
        incrementTableNum();
    }
    ;

}

From source file:org.callimachusproject.sql.SqlTupleResult.java

@Override
public void remove() throws QueryEvaluationException {
    try {/*from w  w  w .ja v a 2  s.com*/
        rs.deleteRow();
    } catch (SQLException e) {
        throw new QueryEvaluationException(e.toString(), e);
    }
}

From source file:org.callimachusproject.sql.SqlTupleResult.java

@Override
public void close() throws QueryEvaluationException {
    try {//from  w  ww  .  j a v  a  2s.  co  m
        rs.close();
        stmt.close();
        conn.close();
    } catch (SQLException e) {
        throw new QueryEvaluationException(e.toString(), e);
    }
}

From source file:com.arsmentis.cordova.jdbc.Jdbc.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("connect".equals(action)) {
        String url = args.getString(0);
        String user = args.getString(1);
        String password = args.getString(2);

        try {//from w w  w  .  j  a va2s  . c  om
            connect(url, user, password);
            callbackContext.success();
        } catch (SQLException e) {
            callbackContext.error(e.toString());
        }

        return true;
    } else if ("disconnect".equals(action)) {
        try {
            disconnect();
            callbackContext.success();
        } catch (SQLException e) {
            callbackContext.error(e.toString());
        }

        return true;
    } else if ("execute".equals(action)) {
        String sql = args.getString(0);

        try {
            JSONArray results = execute(sql);
            callbackContext.success(results);
        } catch (SQLException e) {
            callbackContext.error(e.toString());
        } catch (JSONException e) {
            callbackContext.error(e.toString());
        }

        return true;
    } else if ("load".equals(action)) {
        String driver = args.getString(0);

        try {
            Class.forName(driver);
            callbackContext.success();
        } catch (ClassNotFoundException e) {
            callbackContext.error(e.toString());
        }

        return true;
    } else if ("isConnected".equals(action)) {
        try {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isConnected()));
        } catch (SQLException e) {
            callbackContext.error(e.toString());
        }

        return true;
    }

    return false;
}