I have a table. The table has a column 'Column1' which is of type 'text'.
How can I retrieve the text and store it as a string?
The below is what I attempted. (But it does not work, I get weird characters back, instead of the data within the database)
public void getConfigurationXML()
{
try
{
Class.forName("java.sql.Driver");
Connection conn=(Connection)DriverManager.getConnection(_url,_user,_pwd);
Statement st=conn.createStatement();
ArrayList <String[]> result = new ArrayList<String[]>();
String query ="SELECT Column1 FROM table1";
ResultSet rs=st.executeQuery(query);
int columnCount = rs.getMetaData().getColumnCount();
while(rs.next())
{
String[] row = new String[columnCount];
for (int i=0; i <columnCount ; i++)
{
row[i] = rs.getString(i + 1);
}
result.add(row);
}
rs.close();
st.close();
conn.close();
}
catch(Exception e)
{
Logger lgr = Logger.getLogger(Database.class.getName());
lgr.log(Level.WARNING, e.getMessage(), e);
}
}
If you’re talking about the
textdatatype that is used for BLOB structures, you can try this:The reason for the weird characters is that the database stores this as raw bytes instead of the characters that you’re expecting.