Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- public static String checkPacket(String url,String user,String password){
- String key="";
- String value="";
- Connection con = null;
- Statement st = null;
- ResultSet rs = null;
- try {
- con = DriverManager.getConnection(url, user, password);
- st = con.createStatement();
- rs = st.executeQuery("show variables like 'max_allowed_packet'");
- if (rs.next()) {
- key=rs.getString(1);
- value=rs.getString(2);
- }
- System.out.println("key--->"+key);
- System.out.println("value--->"+Long.parseLong(value));
- rs.close();
- con.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return value;
- }
- public static void main(String[] args) {
- String url = "jdbc:mysql://localhost:3306/db_name";
- String user = "*******";
- String password = "********";
- Connection conn = null;
- try {
- String oldPacketValue=CheckMaxPacket.checkPacket(url,user,password);
- System.out.println("oldPacketValue--->"+oldPacketValue);
- Long oldValue=Long.parseLong(oldPacketValue);
- if(oldValue <= 1024){
- conn = DriverManager.getConnection(url, user, password);
- String querySetLimit = "SET GLOBAL max_allowed_packet=4194304;"; // 104857700 4194304
- Statement stSetLimit = conn.createStatement();
- boolean status = stSetLimit.execute(querySetLimit);
- //System.out.println(status);
- stopMysql();
- startMysql();
- conn.close();
- String newPacketValue=CheckMaxPacket.checkPacket(url,user,password);
- System.out.println("newPacketValue--->"+newPacketValue);
- }else{
- System.out.println("MaxAllowed Packet Is Greater than 1024--->");
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- private static void startMysql() {
- try {
- Runtime.getRuntime().exec("net START MySQL");
- System.out.println("MySQL server started successfully!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void stopMysql() {
- try {
- Runtime.getRuntime().exec("net STOP MySQL");
- System.out.println("MySQL server stopped successfully!");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement