JavaBean Programming Ideas-Read database information

Source: Internet
Author: User

As I said earlier, JavaBean is the implementation: separate the HTML code from the Java code, in the HTML only need to call the Java code on the line, this is called JavaBean.

Now let's share a specific example-read the database, below the specific code + comment

First of all, let's look at JDBC (see another blog for more information on JDBC Programming Basics) directly connected to the database displayed on the page:

This is the first to share the JDBC programming connection database, here I write directly in the JSP.

Good! Here we use JavaBean programming to achieve the same functionality:

The first step: Write a Java class, my JavaBean package defines a Studentdao class

Here I define three functions: query, add, delete, perhaps useful to everyone, here only use the query function, the other functions using the same method.

Step Two: Now write a JSP page to display

Completed, two methods have implemented the same function, the database of students to display the information.

Summary: Using JavaBean to separate the Java Code and HTML code, we see in the client JSP page only a few concise statements, and the implementation of the function is performed on the server side, the client to the server to the JavaBean execution, The server then returns the results of the execution to the client, the entire process client sees only a few simple lines of code in the page, this is the server and the client is separated, and later I will share to you the Servlet programming implementation of the server control layer, then a complete MVC three layer framework is implemented.

For some of these issues, welcome friends to comment, a lot of comments, interested we can discuss together.

JavaBean Programming Ideas-Read database information

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.