Java to the database additions and deletions to check operation __c#

Source: Internet
Author: User

Based on the problems of the previous practice, it can be successfully modified to the database information to check the four basic operations.

The following is part of the modified code, the overall code as detailed in the day before yesterday's Exercise 2. The initial interface will not be said.

First came to the initial interface, click to browse, the database will appear information.



The problem that appears earlier is that after you click Browse, repeated occurrences of the information are added to the form. Then, after looking at the code to understand the error, resolve it.

if (E.getsource () ==view) {
			ResultSet rs=null;
			String v;
			Rs=new usermanage (). view ();
			try {while
				(Rs.next ()) {
					table.setvalueat (rs.getstring ("user_name"), II, 0);
					Table.setvalueat (rs.getstring ("User_type"), II, 1);
					Table.setvalueat (rs.getstring ("StartDate"), II, 2);
					if (Rs.getboolean ("valid") ==true)
						v= "enabled";
					else
						v= "Deactivate";
					Table.setvalueat (V, II, 3);
					ii++;
				}
				ii=0;									No changes before, click Browse, constantly appear data information, the result is added here ii=0 after the solution.
			catch (SQLException E2) {
				e2.printstacktrace ();
			}
		}
Once you have added all the information to the form, you should reset the number of rows to zero so that you can ensure that you are clicking and browsing to see only one set of data. Then, the registration is added. To increase the information in the above input, and then click Register, Show registration success. Add a new line of data under the form

Before the code is no serious work, is perfunctory scholar code, in my epiphany after understand, may not be perfunctory, is a few variables I do not understand what is doing, so I think the code to solve
		if (E.getsource () ==regis) {
			if (new Usermanage (). AddUsers (U_name, U_password, U_type, date, flag)) {
				ResultSet Rs=null;												
				String v;
				Rs=new usermanage (). view ();
				try {while
					(Rs.next ()) {
						table.setvalueat (rs.getstring ("user_name"), II, 0);
						Table.setvalueat (rs.getstring ("User_type"), II, 1);
						Table.setvalueat (rs.getstring ("StartDate"), II, 2);
						if (Rs.getboolean ("valid") ==true)
							v= "enabled";
						else
							v= "Stop";
						Table.setvalueat (V, II, 3);
						ii++;
					}
					ii=0;	
				} catch (SQLException e5) {
					e5.printstacktrace ();}}}
		
After you add the success, use ResultSet to add the form again. The following changes are actually a meaning, after the modification succeeds, add the form again. Modify the time, click on the modified line, the modified username to write, and then enter new information, click Modify, there is a successful modification, new information will appear.
if (new Usermanage (). Isexist (name)) {
What was written before here is (. Parameters), the results later saw a think, he meow should be the name exists, is true, on the implementation ah. Without this person's words, how to modify it.
		if (E.getsource () ==edit) {				//After the modification succeeds, the form displays the question
			if (U_name.equals (")) {
				u_name= (String) table.getvalueat ( Table.getselectedrow (), 0);
			}
			if (new Usermanage (). UpdateUser (U_name, U_password, U_type, date, flag)) {
				ResultSet rs=null;							Solve. Before the modification Oh, is not the information to be added back to the form
				String v;
				Rs=new usermanage (). view ();
				try {while
					(Rs.next ()) {
						table.setvalueat (rs.getstring ("user_name"), II, 0);
						Table.setvalueat (rs.getstring ("User_type"), II, 1);
						Table.setvalueat (rs.getstring ("StartDate"), II, 2);
						if (Rs.getboolean ("valid") ==true)
							v= "enabled";
						else
							v= "Deactivate";
						Table.setvalueat (V, II, 3);
						ii++;
					}
					ii=0;									
				} catch (SQLException E2) {
					e2.printstacktrace ();}}}
		
The last deletion, click the line to delete, click the Delete button, delete the success.
Before the problem is deleted, the form does not update or update there is a problem
 if (E.getsource () ==delete) {//is currently deleted after the form is not with the new int k=0;
			int R=table.getselectedrow ();
			
			String ss= (String) table.getvalueat (r, 0);
				if (new Usermanage (). DeleteUser (ss)) {ResultSet rs=null;
				String v;
				Rs=new usermanage (). view ();
						try {while (Rs.next ()) {Table.setvalueat (rs.getstring ("user_name"), K, 0);
						Table.setvalueat (rs.getstring ("User_type"), K, 1);
						Table.setvalueat (rs.getstring ("StartDate"), K, 2);
						if (Rs.getboolean ("valid") ==true) v= "enabled";
						else v= "Deactivate";
						Table.setvalueat (V, K, 3);
					k++;				} table.setvalueat ("", k,0);				The problem is solved from here, but it is accurate to put the top while table.setvalueat ("", k,1);				The K-OK in the loop is clear, and then in these four lines after the deletion of the form table.setvalueat ("", k,2);				With the new, but the update here can not be said to be updated, because the contents of the while above Table.setvalueat ("", k,3);
				is equivalent to update, here is the last redundant form set to empty can be k=0;
				catch (SQLException E2) {e2.printstacktrace (); }
			}
		}
After you delete it, add the form again, and the last line is empty. After one operation, the information in the database is consistent with the information displayed in the form.

In addition there, there was an episode
String sql= "INSERT into UserInfo (user_name,user_pass,user_type,startdate,valid) VALUES (' +name+" ', ' "+word+" ', ' "+ Type+ "', '" +date+ "", "+f+") ";
At first there's something like this error MySQL encounters check the manual that corresponds to your MySQL server version for the right syntax error
Look for a while, some of the keyword naming problem, and my here is the valid behind one, is it harm, add a statement will have a problem. So, grasp the SQL statements, do not casually change lines, serious and careful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.