jdbc添加问题
我现在添加功能是好用的,前提是:要添加的这个表中必须有至少1条数据,否则会失效,连添加这个链接都点不了,各位大神帮看看被,一下是我的 jdbc 代码。
public int executeUpdate(String sql , int[] types,Object[] values) throws ClassNotFoundException, SQLException, IOException{
System.err.println("更新:"+sql);
this.print(values);
Connection connect = this.getConnection();
PreparedStatement pst = connect.prepareStatement(sql);
if( types != null ){
for(int i=0;i<types.length;i++){
switch( types[i] ){
case Types.VARCHAR:
pst.setString(i+1, String.valueOf( values[i] ) );
break;
case Types.INTEGER:
pst.setInt(i+1, Integer.parseInt( String.valueOf( values[i] ) ));
break;
case Types.BLOB:
InputStream in = new FileInputStream( (File)values[i] );
pst.setBinaryStream(i+1, in , in.available() );
break;
}
}
}
int count = pst.executeUpdate();
this.releaseConnection(pst, connect);
return count;
}