Click here to Skip to main content
15,671,318 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am not able to insert data using setDate in java using prepared statement. Is there any way to resolve this problem?

What I have tried:

String query="insert into Boat(houseboat_id,houseboat_name,houseboat_capacity,booking_date,customer_name,customer_id)values(?,?,?,?,?,?)";
						PreparedStatement pst=c.prepareStatement(query);
						pst.setInt(1, Integer.parseInt(tf1.getText())); 
						pst.setString(2, tf2.getText());
						pst.setInt(3, Integer.parseInt(tf3.getText())); 
						// cannot setdate here
						pst.setInt(6, Integer.parseInt(tf6.getText()));
						JOptionPane.showMessageDialog(null,"Data saved");
					catch(Exception ex )
Updated 28-Apr-21 23:18pm
Richard Deeming 29-Apr-21 4:11am    
How about you start by explaining precisely what the problem is? Remember, we can't see your screen, access your computer, or read your mind. We can't debug your code for you.
Richard MacCutchan 29-Apr-21 4:21am    
Assuming that booking_date is a Date or DateTime type, just add the correct value.

1 solution

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900