In Windows, JSP links MYSQL (JDBC) MYECLIPSE and jdbcmyeclipse

Source: Internet
Author: User

In Windows, JSP links MYSQL (JDBC) MYECLIPSE and jdbcmyeclipse

First download the JDBC driver:


Portal



Create a database in MYSQL


Create database books;


Create tables and insert data:


Use books;
Create table book (bookId varchar (50), bookName varchar (50), publishervarchar (100), price float, constraint pk_book primarykey (bookId) TYPE = MyISAM, default character set gbk; (The bold font is fixed when I create a table, because I didn't use javamxj to add my in windows. INI file practices)

Insert into book values ('123456', 'tomcat and Java Web Development Technical details', 'electronics Industry Press ', 1001 );
Insert into book values ('123456', 'Master Struts: MVC-based Java Web design and developing', 'electronics Industry Publishing House ', 1002 );
Insert into book values ('20170101', 'proficient in Hibernater: detailed explanation of Java object persistence technology ', 'electronics Industry Publishing House', 1003 );
Insert into book values ('20140901', 'ejb proficient ', 'electronics Industry Publishing House', 1004 );
Insert into book values ('20170101', 'j2ee application and BEA Weblogic Server', 'electronics Industry Publishing House ', 1005 );



2. Create a web project named MySQL in Myeclipse:



3. Create a mysql. jsp file. Enter the following code:


<Span style = "font-size: 14px;"> <% @ page contentType = "text/html; charset = gb2312" language = "java" import = "java. SQL. * "%> 
 

4. Copy the mysql-connector-java-3.1.10-bin.jar file to tomcat \ common \ lib


Note: This directory is only limited to TOMCAT 6.0 and less than 6.0.


6.0 solution: place the driver under \ WebRoot \ WEB-INF \ lib of the corresponding project.


5. You can run the jsp file in eclipse.

6. Running result:



Many people cannot connect to the database because of the web. xml file.
Here is the web. xml automatically generated by lomboz:

<span style="font-size:14px;"><?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <display-name>    MySQL</display-name>    <welcome-file-list>        <welcome-file>index.html</welcome-file>        <welcome-file>index.htm</welcome-file>        <welcome-file>index.jsp</welcome-file>        <welcome-file>default.html</welcome-file>        <welcome-file>default.htm</welcome-file>        <welcome-file>default.jsp</welcome-file>    </welcome-file-list></web-app></span>



Jsp connection mysql, jdbc driver in the end where why directly put in the project folder WebRoot \ WEB-INF \ lib is always unable to connect

In fact, if you understand the principle, you can figure it out. There are actually many methods to import the jdbc driver package, but different importing methods have different meanings,
1. Export a package to Tomcat (indicating that the server may use a database, such as a data source). If MyEclipse integrates Tomcat, obviously, you need to right-click the project and choose "Properties"> "Java Build Path"> "Libraries"> "Add JARs" on the right tab... ". If Tomcat is not integrated, copy and paste the driver package in the "common \ lib" folder of the Tomcat root directory.
2. Export the package to the Web Project (indicating that the Web project needs to use the database), copy and paste the driver package to the "Web project \ WEB-INF \ lib" folder.
3. Export the package to a Java Project (indicating that the Web project needs to use the database ), you can choose "right-click Project-> Properties-> Java Build Path-> Libraries-> Add JARs... you can also use the classpath setting method.

How to connect to the MySQL database using jsp files compiled by MyEclipse and install the jdbc driver?

Of course. You can add the jar package of the mysql driver to the lib of the web Project. Then you can call it in jsp and java classes. Search for a mysql driver package online

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.