1

I have defined subjects as

public String[]subjects= {"English","Maths","Science","Social","Programming","Production_Project","20","ENG_MARKS"};

And I have used the following code in prepared statement. but it give me invalid column error in oracle.

JComboBox comboBox = new JComboBox(subjects);
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        Selected_subject = (String)comboBox.getSelectedItem();
        }
    });

Prepared Statement code

JButton btnNewButton_2 = new JButton("Upload");
    btnNewButton_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        String up_assignments = "UPDATE student_assignments set ? = ? WHERE student_id = 2";
        try {
        PreparedStatement ps = connection.prepareStatement(up_assignments);
        ps.setString(1, Selected_subject);
        ps.setInt(2, 25);
        ps.execute();
        }catch(Exception ex)
        {
        ex.printStackTrace();
        }

        }
    });
William Robertson
  • 15,273
  • 4
  • 38
  • 44
  • 1
    Your question is answered here: https://stackoverflow.com/questions/3135973/variable-column-names-using-prepared-statements – Jan Larsen Apr 06 '18 at 12:15
  • @JanLarsen thanks Jan. I found it in the mean time and marked this as duplicate – Piro Apr 06 '18 at 12:16

0 Answers0