As a novice in this card for a long time, is actually a small problem
The calling database does not directly call the data with the JSP, because I don't know why the drive is always poorly configured.
Instead, it intends to use Java to access the database, and then let the JSP call the Java interface
Java code:
Java must have a package of its own and cannot use the default package name
Package Test;import java.sql.*; Public classMysql { PublicMysql () {String driver="Com.mysql.jdbc.Driver"; //the URL points to the database name you want to access ScutcsString URL ="Jdbc:mysql://127.0.0.1:3306/ems"; String User="Root"; String Password=""; Try { //Load DriverClass.forName (driver); Connection Conn=drivermanager.getconnection (URL, user, password); if(!conn.isclosed ()) System. out. println ("succeeded connecting to the database!"); //statement used to execute SQL statementsStatement Statement =conn.createstatement (); //the SQL statement to executeString sql ="SELECT * from Pm2_5"; ResultSet RS=statement.executequery (SQL); System. out. println ("-----------------"); System. out. println ("-----------------"); String name=NULL; while(Rs.next ()) {name= Rs.getstring ("Mark"); //name = new String (name.getbytes ("iso-8859-1"), "Utf-8"); //Output ResultsSystem. out. println (Rs.getstring ("ID") +"\ t"+name); } rs.close (); Conn.close (); } Catch(ClassNotFoundException e) {System. out. println ("Sorry,can ' t find the driver!"); E.printstacktrace (); } Catch(SQLException e) {e.printstacktrace (); } Catch(Exception e) {e.printstacktrace (); } }}
JSP Code:
<%@ page language="Java"Contenttype="text/html; Charset=utf-8"%><%@ page import="java.util.*"import="java.io.IOException"%><%@ page import="test. Mysql"%><% out. println ("haha"); NewMysql ();%>
Console output:
Succeeded connecting to the Database!----------------------------------1e354266e-d5cf-8384-d589-A179f92afee52e354266e-d5cf-8384-d589-A179f92afee53e354266e-d5cf-8384-d589-A179f92afee54e354266e-d5cf-8384-d589-A179f92afee55e354266e-d5cf-8384-d589-A179f92afee56e354266e-d5cf-8384-d589-A179f92afee57e354266e-d5cf-8384-d589-A179f92afee58e354266e-d5cf-8384-d589-A179f92afee59e354266e-d5cf-8384-d589-A179f92afee5Tene354266e-d5cf-8384-d589-A179f92afee5 Onee354266e-d5cf-8384-d589-A179f92afee5 Ae354266e-d5cf-8384-d589-A179f92afee5 -e354266e-d5cf-8384-d589-A179f92afee5 -e354266e-d5cf-8384-d589-A179f92afee5 thee354266e-d5cf-8384-d589-A179f92afee5 -e354266e-d5cf-8384-d589-a179f92afee5
And then encapsulate the Java class on the line ^_^
JSP database operation and invoking the Java class that you wrote