为什么这段代码会导致 NullPointerException?
ArrayList<OrdersAttr> ls = new ArrayList<OrdersAttr>();
OrdersAttr myOrder = null;
String connString = ConnStr.connString;
String connString2 = ConnStr.connString2;
Connection conn = null;
Connection conn2 = null;
Statement stmnt = null;
Statement stmnt2 = null;
String selectString = null;
String insertString = null;
String insertString2 = null;
String updateString = null;
int orderId = 0;
conn = DriverManager.getConnection(connString);
stmnt = conn.createStatement();
selectString = "SELECT A.ORDERID AS ORDERID FROM APP.ORDERS a, APP.CUSTOMER b WHERE ORDERSTATUS = 'NEW ORDER' AND " + " branchid=" + branchid + "and a.CUSTEMAIL = b.EMAIL";
ResultSet rs = stmnt.executeQuery(selectString);
while (rs.next()) {
orderId = rs.getInt("ORDERID");
myOrder = new OrdersAttr();
myOrder.id = rs.getInt("ORDERID");
myOrder.date = rs.getString("datetime");
myOrder.orderitems = rs.getString("orderitems");
myOrder.orderquantity = rs.getString("orderquantity");
myOrder.ordersizes = rs.getString("ordersizes");
myOrder.address = rs.getString("floor_f") + " "
+ rs.getString("building_f") + " "
+ rs.getString("street_f") + " "
+ rs.getString("area_subdivision_district_f") + " "
+ rs.getString("city_f");
myOrder.name = rs.getString("firstname") + " " + rs.getString("lastname");
myOrder.status = rs.getString("ORDERSTATUS");
myOrder.contact = rs.getString("CONTACT");
conn2 = DriverManager.getConnection(connString2);
stmnt2 = conn2.createStatement();
insertString = "INSERT INTO APP.ORDERS VALUES ('" + myOrder.id + "','" + myOrder.date + "','" + myOrder.orderitems + "','" + myOrder.orderquantity + "','" + myOrder.ordersizes + "','" + myOrder.status + "')";
insertString2 = "INSERT INTO APP.CUSTOMER VALUES ('" + myOrder.id + "','" + myOrder.name + "','" + myOrder.address + "','" + myOrder.contact + "')";
stmnt2.executeUpdate(insertString);
stmnt2.executeUpdate(insertString2);
updateString = "UPDATE APP.ORDERS SET ORDERSTATUS = 'SENT TO LOCAL BRANCH'";
stmnt.executeUpdate(updateString);
}
UPDATE String 被执行并更新数据库,但为什么它返回 NullPointerException 并且不执行 INSERT 语句?有人可以帮我解决这个问题。