How to connect to MySQL using JDBC code in JSP webpage

Source: Internet
Author: User

  Tutorial on helping customers (www.bkjia.com)The first step to connect to MySQL using JDBC code in JSP web page is the download of the JDBC driver, in: http://download.sourceforge.net/pub/mirrors/mysql/Downloads/Contrib/mm.mysql.jdbc-1.2c.tar.gz

After the JDBC driver is downloaded, decompress the zip file to any directory. Assume that the directory is d: jdbc, OK! The following describes how to set ClassPAth to ensure that our WebServer can access this driver:

1. Choose my computer> system> set the environment variable. Edit the variable if ClassPAth already exists. Otherwise, add a ClassPAth.

2. Set the value of ClassPAth: d: jdbcmm. mysql. jdbc-1.2cmysql_comp.jar

3. after the server is restarted, after the JDBC settings are complete, many people may not know whether our JDBC installation is successful, we will use a JDBC connection to MySQL to check whether the installation is successful.

The JDBC code in the JSP webpage is as follows:

  1. <% @ Page contentType = "text/html; charset = gb2312" %>
  2. <% Java. SQL. Connection conn;
  3. Java. lang. String strConn; Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
  4. SqlConn = java. SQL. DriverManager. getConnection ("jdbc: MySQL (the best combination with PHP): // localhost/test", "root", ""); %>
Copy code

Related Article

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.