JSP connection mysql actual combat

xiaoxiao2021-03-06  67

[Original]

tack

2003-10-05 Constructing JSP Tomcat MySQL with JSP Tomcat Mysql is an ideal operating environment. In the past, the MySQL function used to PHP, JSP and MySQL connection appeared, and this information is also a little lack, so JSP and database connection becomes the first threshold of beginners, JSP can't connect to the database, undoubtedly It has caused huge hinders to learning. In fact, it will feel very simple across the past. Next, enter the following STEP BY STEP to establish a JSP connection to the mysql process. Please make sure your Tomcat can start, mysql can log in, JSP can run.

First, let's first click on the address of the following address to download the latest (mysql jdbc driver)

http://mysql.linuxforum.net/downloads/connector>

Http://mysql.linux processor-j/mysql-connector-java-3.1.0-alpha.zip "target = _blank>

http://mysql.linuxforum.net/downloads/connector 'Rel = "Nofollow">

http://mysql.linuxforum.net/downloads/connector-j/mysql-connector-java-3.1.0-alpha.zip (you can

Www.mysql.com Update your driver. )

After decompression, put the inside

MySQL-Connector-Java-3.1.0-alpha-bin.jar file is copied to you

Under Tomcat / Common / LIB, restart Tomcat, JSP is completed in the environment of the Mysql.

Next, let's take a JSP to extract the database data:

<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ page import = "java.sql. *"%> <% class.forname ("Org.gjt.mm .mysql.Driver ".) newInstance (); String url =" jdbc:? mysql: // localhost / db_name user = yourusername & password = yourpassword & useUnicode = true & characterEncoding = GB2312 "; Connection conn = DriverManager.getConnection (url); Statement stmt = conn .createstatement (); string query = "select field_name from table_name order = stmt.executequence (query); while (rs.next ()) {string s = rs.getstring (" Field_name "); / / See your field is not a character type, otherwise you can't use getString, use getBoolean and so on, according to field classes,}%> YouruserName And YourPassword changed to your MySQL username and password, the rest of DB_NAME, Field_Name and Table_name also changed to the corresponding name to see the data of your data table? Is not it simple? As long as you know how JDBC is used, the connection to other databases is also a reason. Ok, you can do a lot of things now, continue your JSP trip. Happy journeys!

转载请注明原文地址:https://www.9cbs.com/read-93830.html

New Post(0)