Delete comment from: Javarevisited
Given below is my Java source code for Issuing a book. I want to enter the date of Issue of book in database and I want to pick up that date from the desktop/laptop shows in corner of bottom of screen.
public class Issue extends JFrame {
protected static final String String = null;
private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Issue frame = new Issue();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Issue() {
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setBounds(100, 100, 509, 467);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Book Id");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(177, 128, 92, 14);
contentPane.add(lblNewLabel);
/* JLabel lblNewLabel_1 = new JLabel("Date of Issue");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setBounds(192, 196, 77, 17);
contentPane.add(lblNewLabel_1);*/
textField = new JTextField();
textField.setBounds(309, 125, 86, 20);
contentPane.add(textField);
textField.setColumns(10);
/*textField_1 = new JTextField();
textField_1.setBounds(309, 194, 86, 20);
contentPane.add(textField_1);
textField_1.setColumns(10);*/
final JButton btnIssue = new JButton("Issue");
btnIssue.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me)
{
if(me.getSource()==btnIssue)
{
try
{
**********************Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy/MMM/dd");
String dateNow = formatter.format(currentDate.getTime());
System.out.println("Now the date is :=> " + dateNow);*******************
PreparedStatement ps;
Connection con;
con = ConnectionClass.getCon();
ps=con.prepareStatement("insert into Book_Issue values(?,?)");
ps.setInt(1,Integer.parseInt(textField.getText()));
++++++++ps.setDate(2, "dateNow");++++++++++++
// ps.executeUpdate();
ps.executeUpdate();
JOptionPane.showMessageDialog(null, "THIS BOOK IS ISSUED TO YOU ");
// ps.executeUpdate();
}
catch(Exception sqle)
{
sqle.printStackTrace();
}
}
}
});
btnIssue.setBounds(180, 297, 89, 23);
contentPane.add(btnIssue);
JButton btnNewButton_1 = new JButton("Reset");
btnNewButton_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me1) {
textField.setText("");
textField_1.setText("");
}
});
btnNewButton_1.setBounds(316, 297, 89, 23);
contentPane.add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("Back");
btnNewButton_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg) {
new Confirm().show();
}
});
btnNewButton_2.setBounds(253, 380, 89, 23);
contentPane.add(btnNewButton_2);
}
}
here above the code present in between ***** is of obtaning code from the laptop/desktop and the code betweeen ++++ is the place where I have to use it to display it in database, without writing the date in textfiled.
I hope you would be able to uderstand my query.
plz help me
Mar 18, 2014, 12:41:20 PM
Posted to How to fix java.sql.SQLException: Invalid column index? Example