Backend Development Log (a): User registration

Source: Internet
Author: User

The general requirement is to do a desk lamp project, three professions each have division of labor, we are sent to do an online shopping website. The group of three students in this major, are sister ... To see this situation my intuition is "bad, to do backstage development" ... The hunch is right, that's what it looks like.

July 7, 82 days, the teacher told a simple javaweb example: User login. There are username and password in the database, the match is successful before you can log in, jump to the Welcome screen, display the user name.

The schema is as follows:



|-jspservlet.dao//Storage Interface

|-jspservlet.dao.impl//the implementation class of the storage interface

|-jspservlet.db//Database Connection Operations

|-jspservlet.servlet//used to connect the front and back, don't know what to call

|-jspservlet.vo//user attributes, Getter Setters, feel like JavaBean.







Login easier to get started, the teacher made a new request yesterday: registration.

Because the registration also uses the properties in the user class, I haven't changed it. Userdao is the interface, but also has not changed, but adds a new implementation class Userdaoimpreg, joins the section to add new class Registerservlet.

 PackageJspservlet.dao.impl;Importjava.sql.PreparedStatement;ImportJava.sql.ResultSet;Importjava.sql.SQLException;ImportJspservlet.dao.UserDAO;ImportJspservlet.db.DBConnect;ImportJspservlet.vo.User; Public classUserdaoimpregImplementsuserdao{ Public intQuerybyusername (user user)throwsException {intFlag = 1; String SQL= "SELECT * from UserInfo where username=?"; String Sqladd= "INSERT into Javawebdb.userinfo values (?,?)"; PreparedStatement pstmt=NULL; Dbconnect DBC=NULL; //Database Connection        Try{DBC=NewDbconnect (); Pstmt=dbc.getconnection (). preparestatement (SQL); Pstmt.setstring (1, User.getusername ()); //Query the tuple that corresponds to the input informationResultSet rs =Pstmt.executequery (); //Verify that there is a conflict with a user name already in the database            if( ()) {if(Rs.getstring ("username"). Equals (User.getusername ())) {flag= 0; }            }            if(Flag = = 1){            //writes new user information to the database if it does not conflictPSTMT =dbc.getconnection (). Preparestatement (Sqladd); Pstmt.setstring (1, User.getusername ()); Pstmt.setstring (2, User.getpassword ());            Pstmt.executeupdate ();            } rs.close ();        Pstmt.close (); } Catch(SQLException e) {System.out.println (E.getmessage ()); } finally {            //To close a database connectionDbc.close (); }        returnFlag; }}            

Had not been added executeupdate (), the information is not written in, later found that the problem is here.

The afternoon toss toss a product database, ready to do query function.

Alas, the main is the previous only to learn Java, have not contacted Javaweb, so get started somewhat slow. But the beginning of everything is difficult, tomorrow is expected to be much smoother.

Backend Development Log (a): User registration

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: 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.