简体   繁体   English

即使我已尝试使用SQL中的代码,但在WHERE子句中仍出现错误

[英]I'm getting an ERROR in WHERE Clause even though I've tried the code in SQL

I'm having this very weird ERROR in which when I RUN the program that I connected to SQL,an ERROR appears in which says java.sql.SQLSyntaxErrorException: Syntax error: Encountered "WHERE" at line 1, column 40. 我遇到了一个非常奇怪的错误,当我运行连接到SQL的程序时,出现一个错误,其中说java.sql.SQLSyntaxErrorException:语法错误:在第1行第40列遇到了“ WHERE”。

The Code in other SQL Connection WORKS Perfectly but one this one acts very different, I separated the SQL connection that doesn't work down below. 另一个SQL连接中的代码可以完美工作,但这一行为的功能却截然不同,我在下面分离了无法正常工作的SQL连接。

Please help me solve this problem, Its been hurting my head for 2 days now 请帮我解决这个问题,现在已经疼了我两天了

public void pintransferfunds() {

    //PIN FRAME
    enterpinframe = new JFrame("Enter Pin");
    enterpinframe.setSize(WIDTH, HEIGHT);
    enterpinframe.setVisible(true);
    enterpinframe.setResizable(false);
    enterpinframe.setLocationRelativeTo(null);
    enterpinframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //PIN PANEL  
    enterpinbg = new JPanel();
    enterpinbg.setSize(WIDTH, HEIGHT);
    enterpinbg.setBackground(Color.orange);
    enterpinbg.setVisible(true);
    enterpinbg.setLayout(null);
    enterpinframe.add(enterpinbg);
    JPasswordField inputpin = new JPasswordField();
     inputpin.setFont(new Font("Consolas", Font.BOLD, 20));
     inputpin.setForeground(Color.gray);

     //Setbounds
        inputpin.setBounds(250, 550, 100, 40);

    //tester + image
    enteryourpin = new ImageIcon(getClass().getResource("Enter yout    PIN.png"));
    tester = new JLabel(enteryourpin);
    tester.setBounds(50, 50, 500, 500);

    //enterpin Add
    enterpinbg.add(tester);
    enterpinbg.add(inputpin);


    //exit and option button
    OpEx();
    this.dispose();
    inputpin.addKeyListener(new KeyListener() {
        @Override

        public void keyTyped(KeyEvent e) {
        }
        @Override

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == (KeyEvent.VK_ENTER)) {

                String pinx = inputpin.getText();
                Connection con = null;
                Statement stmt = null;
                try {

                    Class.forName(JDBC_DRIVER1);
                    Class.forName(JDBC_DRIVER2);
                    con = DriverManager.getConnection(URL, USER, PASS);
                    stmt = con.createStatement();
                    String sql = "SELECT*FROM TBL_BANK WHERE PIN ='" + pinx + "' ";
                    ResultSet rs = stmt.executeQuery(sql);
                    while (rs.next()) {
                        pindb = rs.getString("PIN");
                        account_name = rs.getString("ACCOUNT_NAME");
                        balance = rs.getString("BALANCE");
                        id =rs.getInt("ID");

                    }
                    rs.close();

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

                //if Login Success and Failed
                if (pinx.equals(pindb)) {

                    //BALANCE
                    //PIN FRAME
                   frame = new JFrame("OptionFrame");
                    frame.setSize(WIDTH, HEIGHT);
                    frame.setVisible(true);
                    frame.setResizable(false);
                    frame.setLocationRelativeTo(null);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                    //PIN PANEL  
                    panel = new JPanel();
                    panel.setSize(WIDTH, HEIGHT);
                    panel.setBackground(Color.cyan);
                    panel.setVisible(true);
                    panel.setLayout(null);

                    username = new JLabel();
                    username.setBounds(0,0,300,50);
                    username.setText("          Welcome user:"+account_name);
                  panel.add(username);

                    pic = new ImageIcon(getClass().getResource("TranceForm(Sending money).png"));
                    pictester= new JLabel(pic);
                    pictester.setBounds(50,50, 500,500);
                    panel.add(pictester);
                    //Enter amount text
                    JLabel transferFunds = new JLabel("Enter Ammount Php:");
                    transferFunds.setBounds(50,400,200,200);
                    transferFunds.setFont(new Font("Century Gothic",Font.BOLD,20));
                    //Enter receiver Id text
                    JLabel receiverId = new JLabel("Enter Receiver ID:");
                    receiverId.setBounds(50,450,200,200);
                    receiverId.setFont(new Font("Century Gothic",Font.BOLD,20));

                    //Textfield Enter Ammount Php
                    JTextField transferField = new JTextField();
                    transferField.setBackground(Color.white);
                    transferField.setBounds(250,490,200,30);

                    //TextField Enter receiver Id
                     JTextField receiverField = new JTextField();
                    receiverField.setBackground(Color.white);
                    receiverField.setBounds(250,540,200,30);

                      amount =transferField.getText();
                      receive =receiverField.getText();

                    panel.add(receiverId);
                    panel.add(receiverField);

                    panel.add(transferFunds);
                    panel.add(transferField);

                        receiverField.addKeyListener(new KeyListener() {
                       @Override
                       public void keyTyped(KeyEvent e) {

                       }

//HELP ME HERE IS WHERE IT DOESNT WORK //在这里帮我忙

                       @Override
                       public void keyPressed(KeyEvent e) {                           
                        if(e.getKeyCode()==KeyEvent.VK_ENTER)
                        {
                              Connection con = null;
                              Statement stmt =null;
                          try
                          {
                               Class.forName(JDBC_DRIVER1);
                               Class.forName(JDBC_DRIVER2);
                              con= DriverManager.getConnection(URL,USER,PASS);
                               stmt=con.createStatement();


                                String receivesql =("UPDATE TBL_BANK SET BALANCE = BALANCE+"+amount+" WHERE ID = "+receive+"");
                                String sendersql =("UPDATE TBL_BANK SET BALANCE= BALANCE-"+amount+" WHERE ACCOUNT_NAME='"+account_name+"'");
                             stmt.executeUpdate(receivesql);
                               stmt.executeUpdate(sendersql);

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

//END //结束

         if(receiverField.getText().equals(id))
                              {
                               JOptionPane.showMessageDialog(null,"You CANNOT enter your own id");   
                              }
                              else
                              {
                               ImageIcon transImg = new ImageIcon(getClass().getResource("Transform (sending) is sucsseful!.png"));
                               JLabel transimgLoc= new JLabel(transImg);
                              transimgLoc.setBounds(50,50, 500,500);
                              panel.add(transimgLoc);
                              panel.remove(pictester);
                              panel.remove(receiverId);
                              panel.remove(receiverField);
                              panel.remove(transferFunds);
                              panel.remove(transferField);
                              panel.repaint();
                              }

                       }
                       }

                       @Override
                       public void keyReleased(KeyEvent e) {

                       }
                   });



                    frame.add(panel);
                     OpExtrue();
                    enterpinframe.dispose();

                } else if (pinx != (pindb)) {
                    x++;
                    if (x <= 7) {

                        //LoginFailed
                        //if Failed to Login 3 times image icon will change to cop
                        enterpinbg.remove(tester);
                        pinwrong = new ImageIcon(getClass().getResource("PIN Wrong (1_2Times).png"));
                         pinwrongtester = new JLabel(pinwrong);
                         pinwrongtester.setBounds(50, 50, 500, 500);

                        inputpin.setText("");

                        //ADD Frame
                        enterpinbg.add(pinwrongtester);

                        System.out.println(x);
                        enterpinbg.repaint();

                    } else if (x >=8) {
                        enterpinbg.removeAll();

                        enterpinbg.add(inputpin);
                        inputpin.setText("");
                        System.out.println(x);
                        pinwronger = new ImageIcon(getClass().getResource("PIN Wrong2 (Many times).png"));
                        pinwrongertester = new JLabel(pinwronger);

                        pinwrongertester.setBounds(50, 50, 500, 500);
                        enterpinbg.add(pinwrongertester);
                          enterpinbg.add(panelOpEx);
                        enterpinbg.repaint();
                    }
                }
            }
        }

        @Override

        public void keyReleased(KeyEvent e) {

        }

    });

}

Try this, 尝试这个,

    String receivesql = "UPDATE TBL_BANK SET BALANCE = BALANCE + " + amount + " WHERE ID = " + receive + ";";

    String sendersql = "UPDATE TBL_BANK SET BALANCE = BALANCE - " + amount + " WHERE ACCOUNT_NAME = '" + account_name + "';";

    stmt.addBatch(receivesql);
    stmt.addBatch(sendersql);     
    stmt.executeBatch();

You can try this also because you are executing two SQL queries at the same time, 您也可以尝试执行此操作,因为您要同时执行两个SQL查询,

Connection con = null;
Statement stmt = null;
try
{
    Class.forName(JDBC_DRIVER1);
    Class.forName(JDBC_DRIVER2);
    con = DriverManager.getConnection(URL,USER,PASS);
    con.setAutoCommit(false);
    stmt = con.createStatement();

    String receivesql = "UPDATE TBL_BANK SET BALANCE = BALANCE + " + amount + " WHERE ID = " + receive + ";";

    String sendersql = "UPDATE TBL_BANK SET BALANCE = BALANCE - " + amount + " WHERE ACCOUNT_NAME = '" + account_name + "';";

    stmt.executeUpdate(receivesql);
    stmt.executeUpdate(sendersql);

    con.commit();
} catch(Exception x)
{
    System.out.println(x);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使我发送的所有对象都是可序列化的,也会收到NotSerializableException - Getting a NotSerializableException even though all the objects I'm sending are Serializable 为什么我得到了 NotSerializableException 异常,尽管我已经实现了“Serializable” - why I'm getting NotSerializableException exception though I've implemented 'Serializable' 我尝试将 hibernate 与 oracle db 连接,但出现此错误 - I tried to connect hibernate with oracle db,but I'm getting this error 当我返回一个数组时,即使我已经声明了数组,我也会收到“找不到符号”错误 - When I return an array, I'm getting a "cannot find symbol" error even though I have declared the array 获取java.lang.ClassNotFoundException,即使我已经使用-cp指定了正确的jar - Getting a java.lang.ClassNotFoundException even though i've specified the correct jar with -cp 我收到此错误:“即使我已启用必需的提供程序,也没有为此Firebase启用指定的身份验证提供程序。” - I'm getting this error: “The specified authentication provider is not enabled for this Firebase.”, even though I HAVE enabled the required providers 尝试创建和写入文件,但我收到错误消息 - Tried creating and writing to a file, but I'm getting error messages 进程挂在Java中,即使我已经读过(Input / Error)Stream,waitFor()也会永远占用 - Process is hanging in java, waitFor() takes forever even though I've read (Input/Error)Stream 我的 arraylist 尺寸为零,即使我已经向其中添加了项目 - My arraylist size is a zero even though I've added items to the it 我一直试图在地图下方找到一张底页,但遇到了一个错误,我不知道它来自哪里 - i've been trying to get a bottom sheet below on a map and i'm getting an error which i don't know where it's coming from
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM