在使用rowset包的时候遇到了这样的问题:
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)
在网上看了一篇《使用最新sun公司的rowset.jar包的请注意》的文章,用了感觉不太好使,又看了一下sun社区的那篇,里面有种方法,挺好用,也不用修改rowset包,我写了一个CachedRowSet生成类.把自己的代码贴出来,和大家分享。(不知道代码好使不好).
rowset.jar包可以在下面的连接页面下载
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
{//设置资源为中国大陆
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;
}
}
}