private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/vivek";
ResultSet rs = null;
PreparedStatement psmnt = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "vivek", "voyage88");
**psmnt = connection.prepareStatement("insert into save_image(customerid,customername,cnumber,cimage,address,idproof1,idproof2,idc1,idc2,description,ref name,refcnumber,refaddress,refdescription,dates) "
+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");**
String ci = customerid.getText();
psmnt.setString(1, ci);
String cn= customername.getText();
psmnt.setString(2, cn);
String cc= customernumber.getText();
psmnt.setString(3, cc);
is = new FileInputStream(new File(filename));
psmnt.setBinaryStream(4, is);
String ca= address.getText();
psmnt.setString(5, ca);
String id1 = idproof1.getText();
psmnt.setString(6, id1);
String id2 = idproof2.getText();
psmnt.setString(7, id2);
String idcc1=id11.getSelectedItem().toString();
psmnt.setString(8, idcc1);
String idcc2=id22.getSelectedItem().toString();
psmnt.setString(9, idcc2);
String cd= description.getText();
psmnt.setString(10, cd);
String rn= refname.getText();
psmnt.setString(11, rn);
String rc= refcontactnumber.getText();
psmnt.setString(12, rc);
String ra=refaddress.getText();
psmnt.setString(13, ra);
String rd=refdescription.getText();
psmnt.setString(14, rd);
String dte=dtess.getText();
psmnt.setString(15, dte);
int s = psmnt.executeUpdate();
if (s > 0) {
System.out.println("Records sucessfully Added !");
JOptionPane.showMessageDialog(rootPane, "Records sucessfully Added");
} else {
System.out.println("check given records:Records Not Added");
}
connection.close();
psmnt.close();
}
catch (Exception ex) {
System.out.println("Found some error : " + ex);
}
}
我嘗試插入值到XAMPP Mysql使用Java,但得到了錯誤com.mysql.jdbc.packetTooBigExcetion:packet for query is too large(3548177>1048576)-you can change this value on theserver by setting the max_allowed_packet' variable
。如何解決數據包太大的異常XAMPP Mysql
我將my.ini設置1mb更改爲32mb,但錯誤仍在此處。
只需轉到MySQL並執行以下查詢。 set global max_allowed_packet = 100000; – 2014-11-01 06:24:13
還是同樣的錯誤出現 – 2014-11-01 06:30:52
根據你查詢你的數據包尺寸太大就是 錯誤:com.mysql.jdbc.packetTooBigExcetion:包查詢過大(3548177> 1048576) 所以,請儘量設置數據包大小超過3548177. – 2014-11-01 06:32:44