Using MYSQL as an example to describe how to operate a database in JSP:
1. Add the driver of the corresponding database, for example, MySQL is the mysql-connector-java-5.1.25-bin.jar
2. Create the mysqltest. jsp page and enter the following code for testing.
<% @ Page contenttype = "text/html; charset = gb2312" %> <% @ page Language = "Java" %> <% @ page import = "com. mySQL. jbdc. * "%> <% @ page import =" Java. SQL. * "%> <% string drivername =" com. mySQL. JDBC. driver "; string username =" root "; string userpwd =" 123456 "; string dbname =" test "; string tablename =" goods "; string url =" JDBC: mysql: // localhost/"+ dbname + "? User = "+ username +" & Password = "+ userpwd; Class. forname ("com. mySQL. JDBC. driver "). newinstance (); Java. SQL. connection conn = drivermanager. getconnection (URL); out. print ("database connection successful! "); Out. print ("<br>"); Java. SQL. statement statement = Conn. createstatement (); string SQL = "select * from" + tablename; Java. SQL. resultset rs1_statement.exe cutequery (SQL); out. print ("Commodity Code"); out. print ("|"); out. print ("Product Name"); out. print ("|"); out. print ("price (RMB)"); out. print ("<br>"); While (RS. next () {out. print (RS. getstring (1) + ""); out. print ("|"); out. print (RS. getstring (2) + ""); out. print ("|"); out. print (RS. getstring (3) + ""); out. print ("<br>");} Rs. close (); statement. close (); Conn. close (); %>