JSP connection MySQL Database steps:
1. Create MySQL Database script:
Use Uestc;create table emp (empno INT (4) PRIMARY key,ename varchar (ten), Job VARCHAR (9), HireDate date,sal FLOAT (7,2)); INSERT into EMP (empno,ename,job,hiredate,sal) VALUES (6060, ' Zhang San ', ' manager ', ' 2001-09-16 ', 2000.30); INSERT into EMP (empno, Ename,job,hiredate,sal) VALUES (7369, ' John Doe ', ' sales ', ' 2003-10-09 ', 1500.90); INSERT into EMP (empno,ename,job,hiredate,sal) VALUES (7698, ' Harry ', ' Sales ', ' 2005-03-12 ', ' n '), insert into EMP (empno,ename,job,hiredate,sal) VALUES (7762, ' Zhao Liu ', ' Sales ', ' 2005-03-09 ', +); INSERT into EMP (empno,ename,job,hiredate,sal) VALUES (7782, ' Yang Seven ', ' analyst ', ' 2005-01-12 ', 2500); insert into EMP (empno,ename,job,hiredate,sal) VALUES (7839, ' Zhu Eight ', ' manager ', ' 2006-09-01 ', 2500); INSERT into EMP (Empno,ename,job, Hiredate,sal) VALUES (8964, ' money Nine ', ' analyst ', ' 2003-10-01 ', 3000);
2, the MySQL database executes step 1 script, input SELECT * from EMP, the query results as shown;
3. Copy the MySQL driver to the Tomcat6.0\lib directory;
4, write the JSP program listemp.jsp,jsp program as follows:
<%@ page contenttype= "text/html" pageencoding= "GBK"%><%@ page import= "java.sql.*"%>5, enter the virtual path name on the browser http://localhost/uestc/, find the listemp.jsp file, click Open, the results shown are as follows:
Display results show that the JSP program successfully read the MySQL database information, JSP and MySQL connection success!
JSP Connection Database