serialclob을 문자열로 변환하려고합니다. 그러나 나는 성공하지 못했습니다. 나는 내가 올바른 방식으로하지 않는다고 생각한다.serialClob을 String 형식으로 변환하는 방법은 무엇입니까?
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
입니까? 직접 문자열 참조를 비교하는 것
if(type[col] == "CLOB")
:
감사는 이제 또 다른 오류가 같이 표시되어하건를 도왔다. lang.ClassCastException : org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet을 java.sql.ResultSet에 캐스트 할 수 없습니다. – Unknown
@Kiran : 코드에 캐스트가 많이 있습니다. 그것은 일반적으로 코드 냄새입니다. 이제 우리는 Spring SqlRowSet을 사용하고 있음을 볼 수 있었고, 단지'getString'을 사용할 수 있다고 생각합니다. 최소한 시도해 볼만한 가치가 있습니다. –
@Kiran : "serialclob로 값을 가져 오는 중"이라는 것은 무엇을 의미합니까? 솔직히 말해서, 자바를 처음 사용하는 사람이라면 JDBC를 사용하지 말고 먼저 언어와 핵심 플랫폼에 익숙해지고 JDBC와 같은 것들로 이동하십시오. 그렇지 않으면 문제가 API와 관련이 있는지 (또는 * 될지도 모름) 또는 일반적인 자바 경험 부족으로 인해 (첫 번째 문제가 있었는지) 알지 못하는 채로 시도 할 수 있습니다. –