Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

if exists certain line in sql table java condition

public void ftpTableCheck(String host, String port, String username, String password) {
    try {
        String query = "SELECT (count(*) > 0) as found FROM ftp WHERE Host LIKE ? AND Username LIKE ?";
        PreparedStatement pst = conn.prepareStatement(query);
        pst.setString(1, host);
        pst.setString(2, username);

        try (ResultSet rs = pst.executeQuery()) {
            // Only expecting a single result
            if (rs.next()) {
                boolean found = rs.getBoolean(1); // "found" column
                if (found) {
                    // You have rows
                } else {
                    // You have no rows
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #exists #line #sql #table #java #condition
ADD COMMENT
Topic
Name
3+3 =