JSP 连数据库(MySQL & SQLServer2000)
<%@page contentType="text/html;charset=gb2312"%> <% //声名 java.sql.Connection sqlConn; java.sql.Statement sqlStmt; java.sql.ResultSet sqlRst; //regiester jdbc driver
String DBUser="d12345"; String DBPassword="12345678"; String DBServer="s509.now.net.cn"; // Can't use localhost , you must use IP or CNAME String DBNAME="db_abc_com"; // change to your db name Class.forName("org.gjt.mm.mysql.Driver").newInstance(); //connect to the database sqlConn=java.sql.DriverManager.getConnection ("jdbc:mysql://"+DBServer+":3306/"+DBNAME+"?useUnicode=true&characterEncoding=gb2312", DBUser,DBPassword); //create the driver handle sqlStmt=sqlConn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY); //excute sql //sqlRst=sqlStmt.executeQuery("select * from test"); %> Linux-JSP-JDBC-MYSQL TESTING -SELETCT copyright sanry@newsea.net
DB CONNECT OK , |
title |
type |
<%// while(sqlRst.next()) {%>
<%//=sqlRst.getString(1)%> |
<%//=sqlRst.getString(2)%> |
<%//}%>
<% //sqlRst.close(); sqlStmt.close(); sqlConn.close(); %> |