Simple example of a JSP connection mysql

xiaoxiao2021-03-06  69

<% @ Page ContentType = "text / html; charset = GB2312"%>

<% @ page language = "java" import = "java.sql. *"%>

<%

String mysqldriver = "org.gjt.mm.mysql.driver";

String url = "jdbc: mysql: // localhost / hq"; // database connection

CONNECTION CONN;

Class.Forname (mysqldriver);

Conn = drivermanager.getConnection (URL, "root", ""); // username and password

IF (conn == null) {

System.out.println ("Get Conn Error");

}

Statement Stmt = conn.createstatement ();

ResultSet RS = NULL;

RS = stmt.executeQuery ("Select * from news_ART");

While (rs.next ())

{// cyclic display record

%>