Connecting to the MySQL database on the Jsp page

Source: Internet
Author: User

MySQL driver: mysql-connector-java-3.1.7.tar.gz
J2SE version: 5.02
Tomcat version: 5.0.30
MySQL: 4.1.10 or 3.23.49 (my version)
First, extract the MySQL driver and there is a mysql-connector-java-3.1.7 package under the mysql-connector-java-3.1.7-bin.jar. Copy it
JAVA installation directory D: ProgramJava
D: Program FilesJavajre1.5.0 _ 02 libext (used to debug Java programs)
And D: Program FilesJavajdk1.5.0 _ 02jrelibext (the Tomcat Program can also be copied to % CATALINA % commonlib)
Another way is to find a directory to store the MySQL driver. Add the path to the path in the system environment variable.
A Java Application example.
// LoadDriver
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. SQLException;
// Notice, do not import com. mysql. jdbc .*
// Or you will have problems!
Public class LoadDriver {
Public static void main (String [] args ){
Try {
// The newInstance () call is a work around for some
// Broken Java implementations
Class. forName ("com. mysql. jdbc. Driver"). newInstance ();
            }
Catch (Exception ex ){
System. out. println (ex );
        }
    }
}
After debugging, run LoadDriver. class. If no exception is thrown, the driver configuration of the JavaAplication program is successful.
A jsp example

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.