JSP even mysql

zhaozj2021-02-08  190

Download connector / j (mysql-connector-java-3.1.0-alpha.zip) from www.mysql.com, unzipped, copy among the mysql-connector-java-3.1.0-alpha-bin.jar to Web -Inf directory

Establish TEST.JSP, restart Tomcat server <% @ page contenttype = "text / html; charSet = GB2312"%> <% @ page import = "java.sql. *"%> <% class. forName ( "org.gjt.mm.mysql.Driver") newInstance (); String url =. "jdbc: mysql:? // localhost / liufei_com user = root & password = & useUnicode = true & characterEncoding = 8859_1"; // testDB for you database name Connection conn = DriverManager.getConnection (url); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String sql = "select * from users"; ResultSet rs = stmt.executeQuery (sql); while ( rs.next ()) {%> Your first field content is: <% = rs.getstring (1)%> Your second field content is: <% = rs.getstring (2)%> < BR> <%}%> <% out.print ("Database Operation, Congratulations");%> <% rs.close (); stmt.close (); conn.close ();%>

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

New Post(0)