Simple operation of MySQL on JSP page

Source: Internet
Author: User

---restore content starts---

The previous article on the DOS interface to operate MySQL

Now let's talk about how to operate MySQL in a JSP page.

To operate with a JSP page MySQL requires JDBC (not JDBC, and others)

: www.oracle.com

Move to the bottom and find these four boxes, dot the one that's marked up

Find this on the left and click

Then click on any of the two below to adjust to the same interface

I found two things down there.

Choose a click to download, click the two big buttons will tell you to log in, we click on the following "No thanks,just start my Download"

Find a package with a suffix named jar inside it, that's it, CTRL + C

Open your ecplise, create a new project, find this thing, and then CTRL + V

Next, a new JSP page, and then began to write code, the following code is not the best, because in the JSP page is best not to appear Java code,

This is for the intuitive point

First of all, we want to guide the package, do not guide the wrong, the wrong guide, the following code will make an error, here is the three paragraphs written a

This is a path, replace the slash. This path opens in the jar package to find

After knocking over the three lines of code, MySQL is connected. Next, we'll look at the data inserted.

Insert success, then look at the database

Insert multiple lines, code: INSERT into INF values (), ();(on JSP page do not follow the semicolon)

Insert into table name values () ...;

Then the modification

Now is the delete

Insert, UPDATE, delete is finished, now we look at the query, the query needs more code

If you have not learned JDBC (learn JDBC, will initially use), want to see what effect, just the following steps (my is MySQL)

The first step is to create a new Web project

The second step, create a new package, built a class (entity Class), paste the code in the past is good

The third step, according to the code I gave the administrator premise of the doc interface a sentence to lose (every sentence can be successful)

Fourth step, create a new JSP page, paste the code in the past

Where things are built, don't be wrong.

If you create a new package this way, it is a dot src package, dot abc that package, right-click on the Resfreh that is good

Here is the entity class code

 Packageentity;Importjava.sql.Date; Public classEntity {PrivateInteger ID; PrivateString name; PrivateDate Birt;  PublicInteger getId () {returnID; }     Public voidsetId (Integer id) { This. ID =ID; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     PublicDate Getbirt () {returnBirt; }     Public voidSetbirt (Date Birt) { This. Birt =Birt; }        }
The following is the code for the third step

Create DATABASE One;use onecreate table inf (ID int,name varchar), Birt DATE); INSERT into INF values (' 1 ', ' number ', ' 2000-1-1 ') ), (' 2 ', ' second ', ' 2000-1-2 '); INSERT into INF values (' 3 ', ' third ', ' 2000-1-3 '), (' 4 ', ' fourth ', ' 2000-1-4 '); "select * from INF;

Here's the code for the JSP page (you can use the MVC pattern, but it's more straightforward)

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%@ page import=" java.sql.Connection "%><%@ page import=" Java.sql.PreparedStatement "%><%@ page import=" java.sql.ResultSet "%><%@ page import=" Java.util.List, Java.util.ArrayList "%><%@ page import=" entity. Entity "%><%//This is a package of entities class, is a custom 1%><%@ page import=" Java.sql.drivermanager,java.sql.date "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

  

Finally, run the entire project first (note that running the entire project, point project name Run as) Tomcat's not dead.

Tomcat will have a 404 when it starts, leave it alone, and get this copy coming.

Enter the browser, input JSP name, enter

As a result

Well, the article is over here, I hope this article will help you ...

---restore content ends---

Simple operation of MySQL on JSP page

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.