public class Addh001 {
public void add(String h00101,String h00102,int h00103,String h00104,int h00105,int h00106 ,DataSource ds) throws SQLException {
// TODO Auto-generated method stub
Connection conn=null;
try{
conn=ds.getConnection();
System.out.println(h00101+h00102+h00103+h00104+h00105+h00106);
System.out.println("ok");
PreparedStatement ps=conn.prepareStatement("insert into h001 values(?,?,?,?,?,?)");
ps.setString(1, h00101);
ps.setString(2, h00102);
ps.setInt(3,h00103);
ps.setString(4, h00104);
ps.setInt(5,h00105);
ps.setInt(6, h00106);
ps.executeUpdate();
conn.commit();
System.out.println(h00101+h00102+h00103+h00104+h00105+h00106);
conn.commit();
}finally
{
if(conn!=null)
conn.close();
}
}
}
uj5u.com熱心網友回復:
具體的錯誤是什么,貼上來,看看是 oracle 的錯誤,還是 java 的錯誤。uj5u.com熱心網友回復:
java.lang.NullPointerException.uj5u.com熱心網友回復:
你這是 java錯誤啊,除錯下哪一步報的錯uj5u.com熱心網友回復:
借樓,我的也是執行到executeBatch就卡住,樓主問題解決了嗎,求各位大佬幫我看看public static void updateCategory_ID() {
try {
int j=0;
con = DBConn.getConnection();
String sql = "select * from O8100_SPXX_201907_4 where category_id like '%//%' ";
String sql1 = "update O8100_SPXX_201907_4 set category_id =? where goods_id =?";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
con.setAutoCommit(false);
ps = con.prepareStatement(sql1);
while (rs.next()) {
String category_id = rs.getString("category_id");
String[] array = category_id.split(" ");
String category_id1 = "";
for (int i = 0; i < array.length; i++) {
Matcher matcher = Pattern.compile("(com/|item/)(\\d+)").matcher(array[i]);
while (matcher.find()) {
category_id1 = matcher.group(2) + " " + category_id1;
}
}
ps.setString(1, category_id1);
ps.setString(2, rs.getString("goods_id"));
ps.addBatch();
System.out.println(category_id1);
j++;
if(j%1000==0)
{
con.setAutoCommit(false);
ps.executeBatch();
con.commit();
ps.clearBatch();
}
}
ps.executeBatch();
con.commit();// 執行完后,手動提交事務
con.setAutoCommit(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (con != null) {
con.close();
}
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/36532.html
標籤:基礎和管理
