Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am new in this and i can not solve the problem.my code is:

.......
Java
public void actionPerformed(ActionEvent e) {
		String nid = new String(t1.getText());
		String name = new String(t2.getText());
		String phn_no = new String(t3.getText());
		String email = new String(t4.getText());
		String address = new String(t5.getText());
		String room_no = new String(t6.getText());
		String iss_date = new String(t7.getText());
		String res_days = new String(t8.getText());
		String bill_paid = new String(t9.getText());
		String due = new String(t10.getText());
		if (e.getSource() == e1) {
			try{  
				//INSERTING DATA TO CUSTOMER TABLE
				//step1 load the driver class  
				Class.forName("oracle.jdbc.driver.OracleDriver");  
				  
				//step2 create  the connection object  
				Connection conn=DriverManager.getConnection(  
				"jdbc:oracle:thin:@localhost:1521:xe","system","almaksud");  
				  
				//step3 create the statement object  
				Statement stmt=conn.createStatement();  
		
				//step4 execute query  
ResultSet rs=stmt.executeQuery("INSERT INTO CUSTOMER VALUES("+nid+","+name+","+phn_no+","+email+","+address+","+room_no+","+iss_date+","+res_days+","+bill_paid+","+due+ ")");


				while(rs.next()) 
					
				  
				  
				//step5 close the connection object  
				conn.close();  
				  
				}catch(Exception d){ System.out.println(e);}

................
..................
.....................
actually what i am trying to do is that i have created a frame which have 10 textfiedl they are from t1 to t2 and two button "save and exit".
......
Java
String nid = new String(t1.getText());
        String name = new String(t2.getText());
        String phn_no = new String(t3.getText());
        String email = new String(t4.getText());
        String address = new String(t5.getText());
        String room_no = new String(t6.getText());
        String iss_date = new String(t7.getText());
        String res_days = new String(t8.getText());
        String bill_paid = new String(t9.getText());
        String due = new String(t10.getText());

...............
...this part will take string value from text field and pass them to the sql query
Java
ResultSet rs=stmt.executeQuery("INSERT INTO CUSTOMER VALUES("+nid+","+name+","+phn_no+","+email+","+address+","+room_no+","+iss_date+","+res_days+","+bill_paid+","+due+ ")");



if i click the button "save" and then the query will be executed and so every string will be saved in database.please help me.......
Posted
Updated 14-Apr-15 16:23pm
v3
Comments
Mohibur Rashid 14-Apr-15 22:26pm    
So, what happens if you press the save button? What goes wrong? Please be more specific.

Anyway, I can see the error, but lets start from you. You tell us what is happening when you press the save button?

1 solution

You need an Event, that is happening when you push the button.
The values from the textboxes will be read and the command should be triggered to the db.

Please refer here (I strongly recommend to bookmark the link!)

https://docs.oracle.com/javase/tutorial/uiswing/index.html[^]

your specific problem is referenced here:

https://docs.oracle.com/javase/tutorial/uiswing/events/index.html[^]
 
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