娱乐新地带论坛

娱乐新地带论坛 (https://bbs.1819.net/index.php)
-   『网络家园』 (https://bbs.1819.net/forumdisplay.php?f=13)
-   -   请关注JSP连接MYSQL数据库例程 (https://bbs.1819.net/showthread.php?t=9265)

softom 2005-05-28 10:35 AM

请关注JSP连接MYSQL数据库例程
 
请关注JSP连接MYSQL数据库例程

JSP数据库连接说明实例如下:

<%@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");
%>
<html>
<head>
<title>Linux-JSP-JDBC-MYSQL TESTING -SELETCT copyright <a href="mailto: sanry@newsea.net "> sanry@newsea.net </a> </title>
</head>
<body>
<table border="1" cellspace ="0" align="center">
<tr><td>DB CONNECT OK , </td></tr>
<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();
%>
------------------------------------------------------------------------------------------------------


所有时间均为北京时间。现在的时间是 04:38 AM

©2003-2024 1819.net All rights reserved. © 2024