get Single Result String from PreparedStatement - Java java.sql

Java examples for java.sql:ResultSet

Description

get Single Result String from PreparedStatement

Demo Code


//package com.java2s;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    public static String getSingleResultString(PreparedStatement ps)
            throws SQLException {
        String retval;/* ww  w . ja va2  s  .  c o  m*/
        ResultSet rs = ps.executeQuery();
        if (rs.next())
            retval = rs.getString(1);
        else
            retval = null;
        rs.close();
        return retval;
    }
}

Related Tutorials