I've a stupid bracket/parenthesis error that I cannot get right; I am a rookie programmer, Please tell me what punctuation I'm missing;
I am trying to make a Swing GUI
to INSERT
a simple statement to MySQL
based on JComboBox
and JTextArea
selections.
If I had enough reputation points I would be able to screen shot; Here is the updated code with better formatting and the error pointed out.
Thanks!
public class Submit extends JFrame {
DateFormat df = new SimpleDateFormat ("MM/dd/yyyy HH:mm");
Date today = Calendar.getInstance().getTime();
String reqDate = df.format(today);
String[] locations = {"Select School","Union Hills","40th St and Cactus","Chandler","Arrowhead","El Mirage","Surprise","Cactus 1","Cactus 3"};
public JPanel contentPane;
public Submit() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
setTitle("Maintenance Request");
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JComboBox schools = new JComboBox(locations);
schools.setBounds(10, 11, 150, 20);
contentPane.add(schools);
JLabel dater = new JLabel(reqDate);
dater.setBounds(304, 14, 120, 14);
contentPane.add(dater);
JTextArea request = new JTextArea("Type Maintenance Request Here");
request.setLineWrap(true);
request.setBounds(10, 70, 414, 123);
contentPane.add(request);
JButton submitter = new JButton("Submit Request");
submitter.setBounds(145, 204, 144, 23);
contentPane.add(submitter);
submitter.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
Connection connection = null;
Statement insertStmt = null;
{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3307/maintenance","root","password");
insertStmt = connection.createStatement();
insertStmt.executeUpdate("INSERT INTO submit (submit_request,loc_string) VALUES ('"+request.getText()+"','"+schools.getSelectedItem+"')");
}
}); // ERROR here "Syntax error, insert "}" to complete ClassBody"
try
{
insertStmt.close();
connection.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Submit frame = new Submit();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}