惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
小众软件
小众软件
I
InfoQ
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Martin Fowler
Martin Fowler
月光博客
月光博客
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
V
Visual Studio Blog
博客园 - 叶小钗
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - Loviy.Net

从今天开始博客重新开张啦 [cnforums1.2代码学习]4、关于论坛配置的序列化和反序列化做法 [cnforums1.2代码学习]3、论坛的数据库操作流程 - Loviy.Net - 博客园 [cnforums1.2代码学习]2、关于论坛的页面结构 - Loviy.Net - 博客园 [cnforums1.2代码学习]1、论坛的整体结构 XSL的运算符 XSL学习四 - xsl:choose 学习XSL - xsl:if 学习XSL二 - 学习XSL一 学习委托 客户短保存信息(cookie) SQL常用命令使用方法 Sql Server基本函数 常用SQL语句 WebLogic表格对象 经典的鱼和水的对白 用样式定义打印1px表格 女孩子的心思真的难以琢磨
Jsp通过JDBC连接SQL数据库
Loviy.Net · 2004-08-05 · via 博客园 - Loviy.Net

<%--显示数据记录--%>
<%@ page contentType="text/html; charset=GB2312"%>

<html>

<!-- ´´½¨Ò»¸ö HTMLÒ³ÄÜÓÃÀ´ºÍÓû§µÄÇëÇó½øÐн»»¥
-->

<head>
<title>连接数据库</title>
</head>
<body bgcolor=#FFFFFF>
<font face="Helvetica">

<h2>
<font color=#DB1260>
½»»¥²éѯ
</font>
</h2>
<%//引入类库%>
<%@ page import="weblogic.db.jdbc.*,java.sql.*
" %>

<%!
//ÉùÃ÷Êý¾Ý¿âÁ¬½Ó±äÁ¿
Connection conn  = null;
//ÉùÃ÷Êý¾Ý¿âjdbcÇý¶¯±äÁ¿
String jdbcClass ="sun.jdbc.odbc.JdbcOdbcDriver";
//ÉùÃ÷Êý¾Ý¿âurl±äÁ¿
String jdbcURL   = "jdbc:odbc:jdbcsm";


//ÉùÃ÷Êý¾Ý¿âÁ¬½Ó·½·¨
public Connection getCon() {
  
try {
  
//¼ÓÔØÊý¾Ý¿âÇý¶¯³ÌÐò
    Class.forName(jdbcClass).newInstance();
    
//½¨Á¢Êý¾Ý¿âÁ¬½Ó
    conn = DriverManager.getConnection(jdbcURL);
  } 
catch (Exception e) {}
  
return conn;
}
%>

<%
try {
//½¨Á¢Êý¾Ý¿âÁ¬½Ó
  conn = getCon();
  
if (conn != null) {
  
//´´½¨Ö´ÐÐsqlÓï¾äµÄ¶ÔÏó±äÁ¿
    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
     
//Ö´ÐÐsqlÓï¾ä£¬»ñµÃ½á¹û¼¯
    stmt.execute("select * from authors");
    ResultSet ds 
= stmt.getResultSet();
    
//»ñÈ¡ÇëÇó²ÎÊý  
    String myURL  = request.getRequestURI();
    String person 
= request.getParameter("id");
      
    
if (person == null) {
    
//ÁгöËùÓнá¹û
%>

      
<table border=1 cellpadding=5>
        
<th>Employee no</th>
        
<th>Select a name</th>
        
<th>Job</th>
        
<th>Manager</th>
        
<th>Date of hire</th>
        
<th>Salary</th>
        
<th>Commission</th>
        
<th>Dept no</th>

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

        
<tr>
          
<td><%= ds.getString(1!= null ? ds.getString(1) : "&nbsp;" %></td>
          
<td><%= ds.getString(2!= null ? ds.getString(2) : "&nbsp;" %></td>
          
<td><%= ds.getString(3!= null ? ds.getString(3) : "&nbsp;" %></td>
          
<td><%= ds.getString(4!= null ? ds.getString(4) : "&nbsp;" %></td>
          
<td><%= ds.getString(5!= null ? ds.getString(5) : "&nbsp;" %></td>
          
<td><%= ds.getString(6!= null ? ds.getString(6) : "&nbsp;" %></td>
          
<td><%= ds.getString(7!= null ? ds.getString(7) : "&nbsp;" %></td>
          
<td><%= ds.getString(8!= null ? ds.getString(8) : "&nbsp;" %></td>
        
</tr>

<%
      }
%>      

      
</table>

<%
    
//¹Ø±ÕÊý¾Ý¿âºÍÁ¬½Ó
      ds.close();
      conn.close();
      out.flush();
    }
    
else {
    
//´òÓ¡ÇëÇóijһ¸öÈ˵Ľá¹û
%>    

      
<p>
      
<b>½»»¥²éѯ½á¹û</b>:
      
<p>
      ÄãÑ¡ÔñµÄÈËÊÇ: 
<%= person %>

<%
    }
  }
  
else {
  
//Êý¾Ý¿âÁ¬½Ó´íÎó
    out.print("Êý¾Ý¿â²»¿ÉÓá£");
  }
catch (Exception e) {
//Òì³£´¦Àí
  out.print("Exception: " + e);
}
%>


</font>
</body>
</html>

posted on 2004-08-05 17:30  Loviy.Net  阅读(900)  评论(0)    收藏  举报