Java SQL ResultSet String Read getString(ResultSet rs, String name)

Here you can find the source of getString(ResultSet rs, String name)

Description

get String

License

Open Source License

Declaration

public static String getString(ResultSet rs, String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String getString(ResultSet rs, String name) {
        try {/*from  w  ww  .  j av  a  2 s .co m*/
            return "\"" + name + "\":\"" + escapeQuotes(rs.getString(name)) + "\"";
        } catch (SQLException ex) {
            return "\"" + name + "\":\"error\"";
        }
    }

    public static String escapeQuotes(String str) {
        if (str == null || str.isEmpty())
            return "";
        str = str.replaceAll("\n", " ");
        str = str.replaceAll("\\\\", "\\\\\\\\");
        return str.replaceAll("\"", "'");
    }
}

Related

  1. getString(ResultSet rs, int index, boolean trim)
  2. getString(ResultSet rs, int ix, int sql_type)
  3. getString(ResultSet rs, String column)
  4. getString(ResultSet rs, String columnLabel)
  5. getString(ResultSet rs, String columnName)
  6. getString(ResultSet rs, String name, String ifnull)
  7. getStringChunks(ResultSet rs, int colIndex, StringBuffer buf)
  8. getStringFromResultSetEmptyIsNull(ResultSet rset, String fieldName)
  9. getStringList(ResultSet resultSet, String columnName)