JSP connection Mysql/ms SQL server/oracle database connection method [finishing]_jsp programming

Source: Internet
Author: User
Tags stmt oracle database
JSP connection MySQL Database method
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 Tomcat's virtual directory-slightly
Create a jdbcmysql.jsp page
The page code is as follows:
Copy Code code 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 CREATE statement
Stmt.executeupdate (SQL);
OUT.PRINTLN ("Connection successful!") ");
Stmt.close ();
}catch (Exception e) {
Out.println (e);
}
%>
Start Tomcat
Address bar Input: http://localhost:8080/Demo/jdbcMySql.jsp
Test Data Connection Success!
Validating the database
Verify success!
-----The way to connect Ms SQL Server/oracle
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.