serialclobを文字列に変換しようとしています。しかし、私は成功していません。私は正しい方法でやっていないと思う。serialClobを文字列形式に変換するには?
char[] buffer;
int count = 0;
int length = 0;
String data = null;
String[] type;
StringBuffer sb;
try{
SqlRowSet rows = getJdbcTemplate().queryForRowSet("select c.BOUNDING_BOX.GET_WKT() BOUNDING_BOX FROM EXAMPLE c WHERE EXAMPLE_ID = 100",
new Object[] {subid});
SubscriptionModel subscription = new SubscriptionModel();
System.out.println("bbox");
SqlRowSetMetaData rsmd = rows.getMetaData();
type = new String[rsmd.getColumnCount()];
for(int col=0;col<rsmd.getColumnCount();col++)
type[col] = rsmd.getColumnTypeName(col + 1);
System.out.println("Read rows and only serial clob data type values");
while(rows.next()){
System.out.println("test 1 here");
for(int col=0;col<rsmd.getColumnCount();col++){
System.out.println("test 2 here");
if("CLOB".equals(type[col]){
System.out.println("test 3 here");
SerialClob clob = (SerialClob) ((ResultSet) rows).getClob(col + 1);
if(clob != null){
System.out.println("clob is not null");
Reader is = clob.getCharacterStream();
sb = new StringBuffer();
length = (int) clob.length();
if(length>0){
buffer = new char[length];
count = 0;
try{
while((count = is.read(buffer)) != -1)
sb.append(buffer);
data = new String(sb);
}catch(Exception e){
}
}
else
data = (String) null;
}else
data = (String) null;
}else{
data = (String) rows.getObject(col + 1);
}
}
}
return subscription;
}catch(Exception e){
e.printStackTrace();
}
しかし、私はのようなエラーを取得しています:私のコードがある
bbox
Read rows and only serial clob data type values
test 1 here
test 2 here
java.lang.ClassCastException: javax.sql.rowset.serial.SerialClob cannot be cast to java.lang.String
私のミスですか?
感謝は今、別のエラーのような表示されme.Butを助けました。 lang.ClassCastException:org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSetをjava.sql.ResultSetにキャストすることができません。 – Unknown
@Kiran:あなたのコードにキャストがたくさんあります。これは一般的にコードの匂いです。これで、Spring SqlRowSetを使用していることがわかりました。私はあなたが 'getString'を使うことができると考えています...少なくとも、試してみる価値があります。 –
@Kiran:「serialclobとして値を取得しています」とはどういう意味ですか?正直言って、あなたがJavaに慣れていないなら、まずはJDBCから離れて、まず言語とコア・プラットフォームに慣れ、JDBCのようなものに移行してください。それ以外の場合は、問題がAPI固有のもの(これは*可能かもしれない)であるか、Javaの経験が一般的でないか(最初の問題があったため)なので、試してみるだけです。 –