Not recommended to write a statement connection database directly in the JSP page

xiaoxiao2021-03-06  22

1.jsp

<% @ Page ContentType = "text / html; charset = GB2312" Language = "java" import = "java.sql. *"%>

<% ResultSet rs; Connection conn; Statement Stmt; String sql = ""; String userName = "DB_USERNAME"; String userPwd = "DB_PASSWORD"; String serverName = "DB_SERVER"; String DBName = "DATABASE_NAME"; String driverName = "org .gjt.mm.mysql.driver "; class.forname (drivername) .newinstance (); string url =" jdbc: mysql: // " servername " / " DBNAME; conn = drivermanager.getConnection (URL, Username Userpwd;

STMT = conn.createstatement (); sql = "select * from userinfo"; rs = stmt.executeQuery (SQL);

%>

<% while (rs.next ()) {%>

<% = rs.getstring ("Username")%> <%}%>

This can also connect to the database, but will let others see their data source in the source file, not safe, not recommended.

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

New Post(0)