从JTextField中的java GUI将值插入MySQL表

问题描述 投票:0回答:1

我用这个代码,当我按下按钮,它应该值插入数据库

 code  else if(a.getSource()==New){

          try{
            if(Cpphone.getText().equals("")||Dnname.getText().equals("")||array.equals("")|| totalcost==0)
               {
                  JOptionPane.showMessageDialog(this,
                 "Please insert all information before submitting.", "", JOptionPane.INFORMATION_MESSAGE);
                }
            else{          
            Connection mycon= DriverManager.getConnection("jdbc:mysql://localhost:3306/projectofpharmacy","root","sherouk");
            Statement mystat=mycon.createStatement();

            mystat.executeUpdate("insert into pharmacy_orders (patintphone,doctorName,OrderdateTime,totalCost) values ('"+Cpphone.getText()+"','"+Dnname.getText()+"',now(),'"+totalcost+"'");
           JOptionPane.showMessageDialog(this,
                 "the process is done successfuly.", "", JOptionPane.INFORMATION_MESSAGE);

           array=null;
           totalcost=0;

        }   
        }
        catch(Exception e){
            System.out.println(e);

             JOptionPane.showMessageDialog(this,
                 e.toString(), "", JOptionPane.INFORMATION_MESSAGE);

    }

}

我得到这个错误(java.sql.SQLSyntaxErrorException:您的SQL语法错误;检查对应于你的MySQL服务器版本,在1号线附近使用“”正确的语法手册)

java mysql sql database user-interface
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.