JSP connection mysql database

xiaoxiao2021-03-05  61

Method 1: JDBC Download Address: http://dev.mysql.com/get/downloads/connector-j/mysql-connector-java-3.1.8.tar.gz/from/http: //mirrors.sunsite.dk / mysql / unzip mysql-connector-java-3.1.8.tar.gz, put mysql-connection-java-3.1.8-bin.jar in / usr / loacal / under / usr / loacal / mysql-connectctor -java-3.1.8-bin.jar Add to ClassPath Test Page: <% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ Page Import = "Java.SQL. *"%> < % Connection conn; Statement stmt; ResultSet rs; Class.forName ( "com.mysql.jdbc.Driver") newInstance (); conn = DriverManager.getConnection ( "jdbc:.? mysql: // localhost / mysql user = root & password = & useunicode = true & characterencoding = GB2312 "); stmt = conn.createstatement (); rs = stmt.executeQuery (" Select * from user ");%>

DB Connect OK <% While (rs.next ()) {%> <% = rs.getstring (1)%> <% = rs.getstring (2)%> <%}%> <% rs.close (); stmt.close (); conn.close ( );%> Method 2: JDBC connector http://dev.mysql.com/downloads/downloads/Contrib/mm.mysql-2.0.4-bin.jar will M M.MYSQL-2.0.4-bin.jar Path to add ClassPath to test the page: <% @ page contenttype = "text / html; charSet = GB2312"%> <% java.sql.connection sqlconn; java.sql. Statement SQLSTMT; java.sql.resultset Sqlrst; Class.Forname ("org.gjt.mm.mysql.driver") .newinstance (); sqlconn = java.sql.driverManager.getConnection ("JDBC: mysql: // localhost / Mysql? useunicode = true & characterencoding = GB2312 "," root "," "); sqlstmt =

转载请注明原文地址:https://www.9cbs.com/read-31883.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.070, SQL: 9