3 ways to use JDBC to connect to Sybase

Source: Internet
Author: User
Tags generator stmt sybase

1. Test Sybase jconnect-5_2 JDBC Database interface with one JSP file:

<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
< Html>
<TITLE> jsp test Sybase jconnect-5_2 JDBC Database interface </title>
<meta name= " Generator "content=" "EditPlus2.11"
<meta name= "Author" content= "naxin"
<body
<center>jsp test Sybase jconnect-5_2 JDBC Database interface </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> <%out.print ("Successful database operation, congratulations");%>
<%
Rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>

2. Reuse the JSP and Java Bean methods:

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.