Thursday, 15 September 2011

how to convert the type text of MySQL to String in java -



how to convert the type text of MySQL to String in java -

i have probleme in application. in fact not know how convert type text of mysql string in java ?? give thanks you.

string value = resultset.getstring("mytextcolumn");

or maybe so:

stringbuilder sb = new stringbuilder(); bufferedreader br = new bufferedreader( resultset.getclob("mytextclob").getcharacterstrean()); string line; while ((line = br.readline()) != null) { sb.append(line).append("\r\n"); } value = sb.tostring();

best guess

reader in = resultset.getcharacterstream("mycolumn");

see resultset.getcharacterstream.

aha!

as understand there problem in code like:

final string sql = "select description annonce"; seek (preparedstatement stm = connection.preparestatement(sql); resultset rs = stm.executequery()) { while (rs.next()) { string description = rs.getstring("description"); system.out.println("# " + description); } } grab (sqlexception e) { e.printstacktrace(system.out); }

there null returned. description indeed can null, if database field description can (sql) null, prevent that:

create table annonce ( description text not null default ''

or skipt values:

final string sql = "select description annonce description not null";

java mysql string text

No comments:

Post a Comment