Jdbc连Sybase数据库的几种方法,Jdbc连Sybase数据库的几种方法
【 tulaoshi.com - Java 】
1.单用一个JSP文件测试SYBASE jconnect-5_2 JDBC数据库接口: (本文来源于图老师网站,更多请访问http://www.tulaoshi.com/java/)<%@ page contentType="text/html;charset=GB2312" %<%@ page import="java.sql.*" %<HTML<HEAD<TITLE JSP测试SYBASE jconnect-5_2 JDBC数据库接口 </TITLE<META NAME="Generator" CONTENT="EditPlus2.11"<META NAME="Author" CONTENT="naxin"</HEAD<BODY<centerJSP测试SYBASE jconnect-5_2 JDBC数据库接口</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("数据库操作成功,恭喜你");% <%rs.close(); stmt.close(); conn.close(); % </BODY</HTML
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(); %<HRBean的代码: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;}}
来源:http://www.tulaoshi.com/n/20160129/1485285.html
看过《Jdbc连Sybase数据库的几种方法》的人还看了以下文章 更多>>