JSP connection MySQL/ms SQL Server/Oracle Database Connection Methods [finishing]

Source: Internet
Author: User

How to connect JSP to MySQL database
First, copy the MySQL database connection driver to the tomcat/common/lib package.
Download mysql-connector-java-5.1.6.zip
Http://mysql.cs.pu.edu.tw/Downloads/Connector-J/mysql-connector-java-5.1.6.zip
Configure the Tomcat virtual directory-Omitted
Create jdbcmysql. jsp page
Page Code As follows: Copy code The Code is as follows: <% @ page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. SQL. *" %>
<%
Final string mysqldbdriver = "org. gjt. Mm. MySQL. Driver ";
Final string mysqldburl = "JDBC: mysql: // localhost/mldn ";
Final string mysqldbuser = "root ";
Final string mysqldbuserpass = "root ";
Connection con = NULL;
%>
<%
Try {
Class. forname (mysqldbdriver );
Con = drivermanager. getconnection (mysqldburl, mysqldbuser, mysqldbuserpass );
Statement stmt = con. createstatement ();
String SQL = "CREATE TABLE jobs (name varchar (32 ))";
// Execute the create statement
Stmt.exe cuteupdate (SQL );
Out. println ("connection successful! ");
Stmt. Close ();
} Catch (exception e ){
Out. println (E );
}
%>

Start Tomcat
Enter http: // localhost: 8080/demo/jdbcmysql. jsp in the address bar.
Data connection test successful!
Verify Database
Verification Successful!
----- Method for connecting ms SQL Server/Oracle to be continued

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.