Jsp+mysql implementation increase, view function

Source: Internet
Author: User

Preparatory work:

(1) Creating and using the database: Create databases student; Use test;

(2) Creating table: Create TABLE PPP (Sno char (7), sname char (8));

(3) Insert a piece of data: INSERT into PPP values (123,456);

(4) Display data: Select*from PPP; (Review database knowledge)

Begin:

(1) Open myeclipse. Create a new Web project. (Mysql) and build a second.jsp in Webroot

(2) Enter the code in INDEX.JSP:

<body>
<form action= "second.jsp", method= "get" >
User name: <input type= "text" name= "name"/>
Password: <input type= "text" name= "password"/>
<input type= "Submit" value= "register"/>
</form>
</body>


(3) Fill in the following code in SECOND.JSP:

<body>
<%
Connection conn = null;
String driver= "Com.mysql.jdbc.Driver";//Database driver
String username= "root";//Database user name
String userpassword= "123";//Database Password
String dbname= "student";//Database name
String tablename= "PPP";//Table name
String url = "jdbc:mysql://localhost/" + DbName + "? user=" + UserName + "&password=" + userpassword;
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
conn = drivermanager.getconnection (URL);
String name=request.getparameter ("name");//Get form data
String password=request.getparameter ("password");
OUT.PRINTLN (name);//test the form data for outgoing
Statement stmt = Conn.createstatement ();
Stmt.executequery ("SET NAMES UTF8");
String sql = "INSERT into PPP values ('" "+name+" ', ' "+password+" ') ";
try{
Stmt.execute (SQL);
}
catch (Exception e) {}
Stmt.close ();
Conn.close ();
%>

</body>

(4) Program Flowchart:

Input data: 444 555

second.jsp Display:

The database displays:

(5) 444 555 has been added to the database. Only the basic learning, can learn better. How else would you know that better, a comparison



Jsp+mysql implementation increase, view function

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.