画家村吧 关注:202贴子:1,919
  • 0回复贴,共1

JSP 连数据库MySQL

只看楼主收藏回复

<%@page contentType="text/html;charset=gb2312"%> 
<% 
//声名 
java.sql.Connection sqlConn; 
java.sql.Statement sqlStmt; 
java.sql.ResultSet sqlRst; 
//regiester jdbc driver 
Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
//connect to the database 
sqlConn=java.sql.DriverManager.getConnection 
("jdbc:mysql://192.168.0.1:3306/test?useUnicode=true&characterEncoding=gb2312","root",""); 
//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 name"); 
%> 
<html> 
<head> 
<title>Linux-JSP-JDBC-MSSQL TESTING -SELETCT copyright <a href="mailto: sanry@newsea.net "> sanry@newsea.net </a> </title> 
</head> 
<body> 
<table border="1" cellspace ="0" align="center"> 
<tr> 
<th>title </th> 
<th>type </th> 
</tr> 
<% while(sqlRst.next()) {%> 
<tr> 
<td> <%=sqlRst.getString(1)%></td> 
<td><%=sqlRst.getString(2)%></td> 
</tr> 
<%}%> 
</table> 
</body> 
</html> 
<% 
sqlRst.close(); 
sqlStmt.close(); 
sqlConn.close(); 
%> 



1楼2005-02-22 19:48回复