站點首頁   聯系我們 
站點首頁 數據中心 域名註冊 網頁寄存 企業郵局 智能建站  
返回站點首頁
支持中心首頁
常見問題搜索
常見問題
域名相關問題
空間相關問題
郵箱相關問題
智能建站相關問題
繁簡通相關問題
動態域名相關問題
中文域名相關問題
代理申請相關問題
網絡查詢工具
 

   

JSP 連數據庫(MySQL & SQLServer2000)

<%@page contentType="text/html;charset=utf-8"%>
<%
//聲名
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=utf-8", 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();
%>

 

下面是 SQL SERVER 2000的連法

<%@page contentType="text/html;charset=utf-8"%>
<%
//聲名
java.sql.Connection sqlConn;
java.sql.Statement sqlStmt;
java.sql.ResultSet sqlRst;
//regiester jdbc driver
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//connect to the database
sqlConn=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.2:1433;DatabaseName=pubs;SelectMethod=direct","dxxx","");
//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 title_id,title,type from titles");
%>
<html>
<head>
<title>Linux-JSP-JDBC-MYSQL TESTING -SELETCT copyright sanry@newsea.net </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();
%>

 
  打 印   發 送 時代互聯Eranet International Limited 版權所有 ©2005-2024
《中華人民共和國增值電信業務經營許可證》 ISP證粵B2-20042046