Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does JSP connect to Mysql database

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you "JSP how to connect to the Mysql database", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how JSP connects to the Mysql database" this article.

I. Software download

Mysql

Download version: 4.1.11

Http://dev.mysql.com/downloads/mysql/4.1.html

JDBC driver

Download version: 3.1.8

Http://dev.mysql.com/downloads/connector/j/3.1.html

Mysql interface plug-in: mysql-front

Download version image: HongKong (I will come back to install the Chinese version)

Http://www.mysqlfront.de/download.html

II. Software installation

1. Install mysql

As I said above, I refer to saulzy's article and now give a link to saulzy's article:

Http://blog.csdn.net/saulzy/archive/2005/04/23/359648.aspx

It is full of pictures and texts, and it is very clear.

(thanks again to saulzy)

2.JDBC driver: mysql-connector-java-3.1.8

This is just a compressed package, do not need to install, just unzip it, we use the file in the folder mysql-connector-java-3.1.8: mysql-connector-java-3.1.8-bin.jar.

3. Mysql interface plug-in: mysql-front

This is an installer, just follow the prompts to install it.

III. Environment configuration

First of all, I would like to make it clear that I am now

The installation path for tomcat is: D:Program FilesJavaTomcat

The installation path for JDK is: D:Program FilesJavaj2sdk

Here, it is the JDBC driver that needs to configure the environment variables. Before configuring, you need to put the mysql-connector-java-3.1.8-bin.jar local hard disk somewhere (where I put it: D:Program FilesJavamysqlforjdbc), and then configure classpath according to where you put it. My configuration is like this:

; D:Program filesJavaj2sdklib ools.jar;D:Program FilesJavaj2sdklibmysql-connector-java-3.1.8-bin-g.jar;D:Program FilesJavamysqlforjdbcmysql-connector-java-3.1.8-bin.jar

The purpose of configuring this is to let your java application find the driver that connects to mysql.

After configuring the environment variables, there is also a very important step is to configure the driver for the JSP connection database. This is actually very simple, just copy the mysql-connector-java-3.1.8-bin.jar to some folders. I read a lot of information on the Internet and asked a lot of people. There are all kinds of opinions. I synthesized it. I did it all for the sake of insurance. Hehe, anyway, I just copied a 400K file. Now list the folders to which you want to copy mysql-connector-java-3.1.8-bin.jar, as follows:

D:Program FilesJavaTomcatcommonlib

D:Program FilesJavaTomcatsharedlib

Four. use of database

After the installation of Mysql, there are still some points to pay attention to. Saulzy has also written an article here, which you will see clearly. The connection is as follows: http://blog.csdn.net/saulzy/archive/2005/04/23/359811.aspx

As mentioned in the saulzy article, the most important thing after mysql installation is to see whether the database has been started as a system service, so before you do the database operation, you should take a look at the

Start-> run-> enter services.msc to make sure that the mysql service you set up during installation has been started, so that you will not report a connection error when operating the database.

There is a convenient mysql interface plug-in mentioned above, but I found this interface only after I have started using mysql. At first, I operated on the command line under dos. Although that interface can also build libraries, set permissions and other operations, I think it is also a very important skill to use the command line, so I'll start with the command line. How to simply use mysql. I'll talk about the use of mysql-front later.

Now I want to build a database shujuku in mysql and a table biao in the database. The specific commands are as follows (assuming I just installed mysql)

1. Enter the dos state (remember that the command line will run in the bin directory under the installation directory of mysql) as follows:

two。 Connect mysql

Enter: mysql? h localhost? U root? P

An interface that requires a password appears (see figure 2)

Enter the password that has been set during installation and enter the command editing interface of mysql nearby, as shown in figure 3:

3. Basic commands for using mysql (be sure to have a semicolon at the end of each mysql command line editor after entering a command, otherwise an error will be reported)

Show database: show databases

Use database: use database name

An example is shown in figure 4:

4. Build a database

Command: create database shujuku

5. Set permissions (user and password) for the database

Command: grant all privileges on shujuku.* to test@localhost identified by "123456"

After you execute this command, as long as you log in with the user name: test, password: 123456, you can only operate on the shujuku database, which avoids using root, which is of great help to the security of the database. Figure 5

6. Build a table

Command: create table biao (id int (8) primary key,name varchar (10))

Figure 6

The rest is basically the same as the standard sqsl command, and the specific operation is slightly

It is worth mentioning that you typed "on the command line"? "there will be simple help with the mysql command, as shown in figure 8:

Ha ha, that way, we can also know to quit, is "exit", ha ha!

V. on the use of mysql-front

I found several mysql interface tools, I think the most concise and convenient is mysql-front, but it is a pity to charge, but fortunately there is a trial period, hehe, you can feel it first, the most important point is that mysql-front has a simplified Chinese version, English is not good, I am much more comfortable to use.

First of all, the installation is needless to say, there is a wizard, and it is very simple. After installation, the first run will pop up a box asking to add a dialog, where you can add, for example, the shujuku already set above, as shown in figure 9, 10, 11:

After you fill in the user name and password you set in mysql above in the check box for registration, you will have the shujuku database in the select database box. Select and press OK. After entering mysql-fron, you will see the following interface, which is where you can operate. Figure 12

To be clear, you can also add root users, which requires you to choose from the mysql-fron interface.

Settings-> dialogue-> New, and then press the above can be done, out of root you can also join more users, the method is still the same, set up different users, is convenient to manage different databases, ha ha, root is the highest authority, do not casually let others use your root users, to ensure the security of your database.

VI. JSP connects to mysql

Now it's time to try to connect to mysql with jsp.

I set up a test_mysql.jsp page in eclipse with the following code:

Then deploy test _ mysql.jsp to tomcat

Undefinedundefinedundefinedundefined

The above is all the contents of the article "how JSP connects to Mysql database". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report