在使用rowset包的時(shí)候遇到了這樣的問(wèn)題:
java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:80)
at java.util.Properties.load(Properties.java:266)
at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:96)
at com.sun.rowset.JdbcRowSetResourceBundle.<init>(JdbcRowSetResourceBundle.java:92)
at com.sun.rowset.JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle(JdbcRowSetResourceBundle.java:114)
at com.sun.rowset.CachedRowSetImpl.<init>(CachedRowSetImpl.java:360)Exception: null
at com.sun.rowset.WebRowSetImpl.<init>(WebRowSetImpl.java:68)
at test.Test.generateXML(Test.java:98)
at test.Test.main(Test.java:168)
在網(wǎng)上看了一篇《使用最新sun公司的rowset.jar包的請(qǐng)注意》的文章,用了感覺(jué)不太好使,又看了一下sun社區(qū)的那篇,里面有種方法,挺好用,也不用修改rowset包,我寫(xiě)了一個(gè)CachedRowSet生成類(lèi).把自己的代碼貼出來(lái),和大家分享。(不知道代碼好使不好).
rowset.jar包可以在下面的連接頁(yè)面下載
http://java.sun.com/products/jdbc/download.html#rowsetcobundle1_0
import javax.sql.rowset.CachedRowSet;
import com.sun.rowset.CachedRowSetImpl;
import java.util.Locale;
import java.sql.*;
public class cachedRowsetCreater {
protected CachedRowSet crs=createCachedRowset();
public void close(){
try {
crs.release();
}
catch (SQLException ex) {
}
crs=null;
}
public cachedRowsetCreater(String JNDI_NAME) throws Exception {
crs.setDataSourceName(JNDI_NAME);
}
public CachedRowSet createCachedRowset() throws SQLException
{
Locale locale = Locale.getDefault ();
try
{//設(shè)置資源為中國(guó)大陸
Locale.setDefault (Locale.CHINESE);//在linux下好像要用CHINA
return new CachedRowSetImpl ();
}
finally
{
Locale.setDefault (locale);
}
}
public CachedRowSet executeQuery(String QueryString){
try{
CachedRowSet crs1=crs.createCopySchema();
crs1.setCommand(QueryString);
crs1.execute();
return crs1;
}catch(SQLException e){
return null;
}
}
}