Beginner JSP users often ask how to connect, I concentrated in this article for your reference, now start our JSP and database trip! ● JSP connection mysql database TestMysql.jsp is as follows: <% @ Page ContentType = "Text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%>
<% class.forname ("org.gjt.mm.mysql.driver" ) .newInstance (); String url = "jdbc:? mysql: // localhost / softforum user = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1" // testDB for your database name Connection conn = DriverManager.getConnection (url); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String sql = "select * from test"; ResultSet rs = stmt.executeQuery (sql); while (rs.next ()) {%> your first Field content is: <% = rs.getstring (1)%> Your second field content is: <% = rs.getstring (2)%> <%}%> <% out.print ("Database operation success Congratulations, ");%> <% rs.close (); stmt.close (); conn.close ();%> body> html>