隨筆 - 100  文章 - 50  trackbacks - 0
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          我收藏的一些文章!

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          一、jsp連接Oracle8/8i/9i數(shù)據(jù)庫(用thin模式)

          testoracle.jsp如下:
          < %@ page contentType="text/html;charset=gb2312"% >
          < %@ page import="java.sql.*"% >
          < html >
          < body >
          < %Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
          String url="jdbc:oracle:thin:@localhost:1521:orcl";
          //orcl為你的數(shù)據(jù)庫的SID
          String user="scott";
          String password="tiger";
          Connection conn= DriverManager.getConnection(url,user,password);
          Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
          String sql="select * from test";
          ResultSet rs=stmt.executeQuery(sql);
          while(rs.next()) {% >
          您的第一個(gè)字段內(nèi)容為:< %=rs.getString(1)% >
          您的第二個(gè)字段內(nèi)容為:< %=rs.getString(2)% >
          < %}% >
          < %out.print("數(shù)據(jù)庫操作成功,恭喜你");% >
          < %rs.close();
          stmt.close();
          conn.close();
          % >
          < /body >
          < /html >


          二、jsp連接Sql Server7.0/2000數(shù)據(jù)庫


          testsqlserver.jsp如下:
          < %@ page contentType="text/html;charset=gb2312"% >
          < %@ page import="java.sql.*"% >
          < html >
          < body >
          < %Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
          String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
          //pubs為你的數(shù)據(jù)庫的
          String user="sa";
          String password="";
          Connection conn= DriverManager.getConnection(url,user,password);
          Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
          String sql="select * from test";
          ResultSet rs=stmt.executeQuery(sql);
          while(rs.next()) {% >
          您的第一個(gè)字段內(nèi)容為:< %=rs.getString(1)% >
          您的第二個(gè)字段內(nèi)容為:< %=rs.getString(2)% >
          < %}% >
          < %out.print("數(shù)據(jù)庫操作成功,恭喜你");% >
          < %rs.close();
          stmt.close();
          conn.close();
          % >
          < /body >
          < /html >


          ?


          三、jsp連接DB2數(shù)據(jù)庫


          testdb2.jsp如下:
          < %@ page contentType="text/html;charset=gb2312"% >
          < %@ page import="java.sql.*"% >
          < html >
          < body >
          < %Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
          String url="jdbc:db2://localhost:5000/sample";
          //sample為你的數(shù)據(jù)庫名
          String user="admin";
          String password="";
          Connection conn= DriverManager.getConnection(url,user,password);
          Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
          String sql="select * from test";
          ResultSet rs=stmt.executeQuery(sql);
          while(rs.next()) {% >
          您的第一個(gè)字段內(nèi)容為:< %=rs.getString(1)% >
          您的第二個(gè)字段內(nèi)容為:< %=rs.getString(2)% >
          < %}% >
          < %out.print("數(shù)據(jù)庫操作成功,恭喜你");% >
          < %rs.close();
          stmt.close();
          conn.close();
          % >
          < /body >
          < /html >


          四、jsp連接Informix數(shù)據(jù)庫


          testinformix.jsp如下:
          < %@ page contentType="text/html;charset=gb2312"% >
          < %@ page import="java.sql.*"% >
          < html >
          < body >
          < %Class.forName("com.informix.jdbc.IfxDriver").newInstance();
          String url =
          "jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver;
          user=testuser;password=testpassword";
          //testDB為你的數(shù)據(jù)庫名

          posted on 2006-08-11 16:50 fly 閱讀(183) 評(píng)論(0)  編輯  收藏 所屬分類: jsp學(xué)習(xí)
          主站蜘蛛池模板: 康乐县| 敦化市| 贵定县| 辰溪县| 色达县| 北安市| 临清市| 莱阳市| 泰顺县| 黄浦区| 新泰市| 阿巴嘎旗| 大悟县| 沽源县| 库尔勒市| 西吉县| 洪雅县| 淮北市| 白河县| 公安县| 临江市| 陆川县| 新民市| 嘉禾县| 江西省| 湟源县| 乌恰县| 喀喇| 万全县| 明水县| 内乡县| 咸阳市| 元谋县| 灵川县| 增城市| 正阳县| 兴国县| 美姑县| 黑龙江省| 景泰县| 仁布县|