主頁 > 知識庫 > Jdbc連Sybase數(shù)據(jù)庫的幾種方法

Jdbc連Sybase數(shù)據(jù)庫的幾種方法

熱門標(biāo)簽:電銷外呼系統(tǒng) 排行榜 四川電信外呼系統(tǒng)靠譜嗎 地圖標(biāo)注創(chuàng)業(yè)項目入駐 珠海銷售外呼系統(tǒng)運(yùn)營商 廣州三五防封電銷卡 地圖標(biāo)注制作道路 長春回?fù)芡夂粝到y(tǒng)廠家 山東智能云外呼管理系統(tǒng) 外呼系統(tǒng)啥意思
1.單用一個JSP文件測試SYBASE jconnect-5_2 JDBC數(shù)據(jù)庫接口

%@ page contentType="text/html;charset=GB2312" %>%@ page import="java.sql.*" %>HTML>HEAD>TITLE> JSP測試SYBASE jconnect-5_2 JDBC數(shù)據(jù)庫接口 /TITLE>META NAME="Generator" CONTENT="EditPlus2.11">META NAME="Author" CONTENT="naxin">/HEAD>BODY>center>JSP測試SYBASE jconnect-5_2 JDBC數(shù)據(jù)庫接口/center>BR>BR>table border=3 align=center >%Class.forName("com.sybase.jdbc2.jdbc.SybDriver");String url ="jdbc:sybase:Tds:localhost:2638"; Connection conn= DriverManager.getConnection(url, "dba","sql"); Statement stmt=conn.createStatement(); String sql="select emp_lname,dept_id,street,city,state from employee order by emp_lname"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {out.print("TR>TD>"+rs.getString("emp_lname")+"/TD>");out.print("TD>"+rs.getString("dept_id")+"/TD>");out.print("TD>"+rs.getString("street")+"/TD>");out.print("TD>"+rs.getString("city")+"/TD>");out.print("TD>"+rs.getString("state")+"/TD>/TR>");}%> /table>BR>HR>%out.print("數(shù)據(jù)庫操作成功,恭喜你");%> %rs.close(); stmt.close(); conn.close(); %>  /BODY>/HTML>


2.再用JSPJava Bean的方法:
JSP Code:%@ page contentType="text/html;charset=GB2312" %>%@ page import="java.sql.*" %>HTML>HEAD>TITLE>  /TITLE>META NAME="Generator" CONTENT="EditPlus2.11">META NAME="Author" CONTENT="naxin">/HEAD>BODY>jsp:useBean id="sybase" scope="page" class="test.sybconn" />%ResultSet rs=sybase.Query("select * from tjck_dh"); while(rs.next()) {out.print("|"+rs.getString("name")+"|");out.print(rs.getString("card_no")+"|");out.print(rs.getString("amount")+"|");out.print(rs.getString("home_call")+"|");out.print(rs.getString("office_call")+"|br>");}rs.close(); %>HR>Bean的代碼:package test;import java.sql.*;public class sybconn {// String sDBDriver = "com.sybase.jdbc2.jdbc.SybDriver";  String sConnStr = "jdbc:sybase:Tds:localhost:2638";// String user="dba";// String passwd="sql";Connection conn = null;ResultSet rs = null;public ResultSet Query(String sql) throws SQLException,Exception {Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();conn = DriverManager.getConnection(sConnStr,"dba","sql");Statement stmt = conn.createStatement();rs = stmt.executeQuery(sql);return rs;}}


3.
利用JDBC(SYBAE jconnect-5_2)查詢Sybase ASA7.0中數(shù)據(jù)的圖形化Java程序范例:
////   一個簡單的利用JDBC(SYBAE jconnect-5_2)查詢Sybase ASA7.0中數(shù)據(jù)的圖形化Java程序范例//    執(zhí)行的SQL語句是" select * from employee "  ,可以改成自己所需的.//    運(yùn)行方式為: c:\&; java JDBCTest  //import java.awt.*;      import java.sql.*;   // 在使用JDBC之前,必須引入JAVASQLclass JDBCTest extends Frame {TextArea myTextArea;public JDBCTest () {//設(shè)定程序的顯示界面super("一個簡單的利用JDBC(jconnect-5_2)查詢Sybase ASA7.0中數(shù)據(jù)的圖形化Java程序范例");setLayout(new FlowLayout());myTextArea = new TextArea(30,80);add(myTextArea);resize(500,500);show();myTextArea.appendText("數(shù)據(jù)庫查詢中,請等待......\n");}void displayResults(ResultSet results) throws SQLException {//首先得到查詢結(jié)果的信息ResultSetMetaData resultsMetaData = results.getMetaData();int cols = resultsMetaData.getColumnCount();//將等待信息清除myTextArea.setText("");//顯示結(jié)果while(results.next()) {for(int i=1;i=cols;i++) {if(i>1)myTextArea.appendText("\t");try{myTextArea.appendText(results.getString(i));}// 捕獲空值時產(chǎn)生的異常catch(NullPointerException e){}}myTextArea.appendText("\n");}}public boolean handleEvent(Event evt) {if (evt.id == Event.WINDOW_DESTROY) {System.exit(0);return true;}return super.handleEvent(evt);}public static void main(String argv[]) throws SQLException,Exception {//設(shè)定查詢字串String queryString = "select * from employee";JDBCTest myJDBCTest = new JDBCTest();//加載驅(qū)動程序Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();//建立連接,localhost為主機(jī)名,dba為用戶名,sql為密碼Connection myConn = DriverManager.getConnection("jdbc:sybase:Tds:localhost:2638","dba","sql");Statement myStmt = myConn.createStatement();//執(zhí)行查詢ResultSet myResults = myStmt.executeQuery(queryString);myJDBCTest.displayResults(myResults);//關(guān)閉所有打開的資源myResults.close();myStmt.close();myConn.close();}}  

標(biāo)簽:紹興 保定 北海 玉樹 廣元 吳忠 肇慶 潮州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Jdbc連Sybase數(shù)據(jù)庫的幾種方法》,本文關(guān)鍵詞  Jdbc,連,Sybase,數(shù)據(jù)庫,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Jdbc連Sybase數(shù)據(jù)庫的幾種方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于Jdbc連Sybase數(shù)據(jù)庫的幾種方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章