错误:
Exception in thread "main" java.lang.NullPointerException
at com.mysql.jdbc.UpdatableResultSet.syncUpdate(UpdatableResultSet.java:1550)
at com.mysql.jdbc.JDBC4UpdatableResultSet.updateNString(JDBC4UpdatableResultSet.java:311)
at com.mysql.jdbc.JDBC4UpdatableResultSet.updateNString(JDBC4UpdatableResultSet.java:345)
at cn.ailab.patentmining.dao.Write.writeToDB(Write.java:45)
at cn.ailab.patentmining.core.cluster.kmeans.CoreKmeans.coreKmeans(CoreKmeans.java:68)
at cn.ailab.patentmining.test.core.execute.main(execute.java:12)
代码:
Connection con = MysqlUtil.getInstance().getConn();
if( con == null )
System.out.println(1);
Statement stmt = (Statement)con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
if( stmt == null )
System.out.println(2);
String sql = "create table clusterResult("+
"id nvarchar(30) null, "+
"n1 nvarchar(30) null, "+
"n2 nvarchar(30) null, "+
"n3 nvarchar(30) null, "+
"n4 nvarchar(30) null, "+
"n5 nvarchar(30) null, "+
"n6 nvarchar(30) null, "+
"n7 nvarchar(30) null, "+
"primary key(id));";
//System.out.println(sql);
stmt.executeUpdate(sql);
ResultSet rs = stmt.executeQuery("select id,n1,n2,n3,n4,n5,n6,n7 from clusterResult where id is null");
if( rs == null )
System.out.println(3);
String ss;
ss = "xf";
rs.updateNString("id", ss); //出错的地方
rs.insertRow();
关于mysql链接的代码:
public class MysqlUtil {
private static MysqlUtil mysqlUtil;
private MysqlUtil() {
}
public static MysqlUtil getInstance() {
if (null == mysqlUtil) {
mysqlUtil = new MysqlUtil();
}
return mysqlUtil;
}
static {
try {
Class.forName("com.mysql.jdbc.Driver");// 加载驱动
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
// 获取连接
public Connection getConn() {
try {
return DriverManager.getConnection(MysqlPrameters.URL, MysqlPrameters.USER,
MysqlPrameters.PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
// 释放资源
public void release(ResultSet rs, Statement st, Connection conn) {
if (null != rs) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (null != st) {
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (null != conn) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
代码我是修改别人的,需要增加一个把内容写入到数据库的功能,但是出错了。求大牛解答。(前面还要利用mysql链接那个类从数据库里面读入数据,是不是对写有影响的?)
--转自