0

How can I replace the single backslashes "\"in the string filepath with either double backslashes "\" or a single slash "/" ? I need it so that i can execute the desktop method in java properly

here is the code:

    JButton btnAdd = new JButton("Add");
    btnAdd.setBounds(101, 560, 89, 23);
    frmAddContract.getContentPane().add(btnAdd);
            btnAdd.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {

            try{

                String cntr = ContractNo.getText();
                String en = EngagerName.getText();
                String cont = contNo.getText();
                String mo = month.getText();
                String d = day.getText();
                String yr = year.getText();
                String dte = yr + "-" + mo + "-" + d;
                String cla = cladd.getText();
                String tm = tme.getText() + ":00";
                String evadd = eventadd.getText();
                String filepath = textField_fp.getText();
                String ref = refer.getText();





                String SQL = "insert into cis "+
                    "values ('"+cntr+"','"+en+"','"+
                    cont+"','"+cla+"','"+dte+"','"+tm+"','"+
                    evadd+"','"+filepath+"','"+ref+"');";
                PreparedStatement stmt = conn.prepareStatement(SQL);
                stmt.executeUpdate();
                JOptionPane.showMessageDialog(null, "Addition of Contract Successful!");
                frmAddContract.setVisible(false);
                PreparedStatement show = conn.prepareStatement("select * from kusinanikambal.cis;");
                ResultSet rs = show.executeQuery();
                System.out.println(rs.getRowId("engager"));


            }
            catch(Exception e){
                JOptionPane.showMessageDialog(null, e);
            }
                }


            });

1 Answers1

0
String filepath = textField_fp.getText().replaceAll("\\\\","\\\\\\\\");
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152