Several methods of JDBC even Sybase database

Source: Internet
Author: User
Tags dba generator query stmt sybase sybase database
Data | database


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

FFFF00 border=1>
<%@ page contenttype= "text/html;charset=gb2312"%><%@ page import= "java.sql.*"%>


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" >


3. Use JDBC (sybae jconnect-5_2) to query examples of graphical Java programs for data in Sybase ASA7.0:
A simple example of a graphical Java program using JDBC (sybae jconnect-5_2) to query data in Sybase ASA7.0//Executing SQL statements is "SELECT * from Employee" and can be changed to its own needs.      Operation mode is: c:\> java jdbctest//import java.awt.*;   Import java.sql.*; Before using JDBC, you must introduce Java SQL Package class Jdbctest extends Frame {TextArea mytextarea;public jdbctest () {//Set Program Display interface Super (" A simple example of using JDBC (jconnect-5_2) to query the graphical Java programs for data in Sybase ASA7.0); SetLayout (new FlowLayout ()); Mytextarea = new TextArea ( 30,80); add (Mytextarea); resize (500,500); show (); Mytextarea.appendtext (in database queries, please wait ... \ n);} void DisplayResults (ResultSet results) throws SQLException {//First get information about the results of the query ResultSetMetaData Resultsmetadata = Results.getmetadata (); int cols = Resultsmetadata.getcolumncount ();//Will wait for information clear Mytextarea.settext ("");//display result while ( Results.next ()) {for (int i=1;i<=cols;i++) {if (i>1) mytextarea.appendtext ("\ t"); Try{mytextarea.appendtext ( Results.getstring (i)); The exception catch (NullPointerException e) {}}mytextarea.appendtext ("\ n") is generated when a null value is caught; 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 {//Set query string string querystring = "SELECT * FROM Employee "; Jdbctest myjdbctest = new Jdbctest ()//Load Driver Class.forName ("Com.sybase.jdbc2.jdbc.SybDriver"). Newinstance ()//Establish a connection , localhost is the hostname, the DBA is the username, SQL is the password connection myconn = drivermanager.getconnection ("jdbc:sybase:tds:localhost:2638", " DBA "," SQL "); Statement mystmt = myconn.createstatement ()//execute query ResultSet myresults = Mystmt.executequery (querystring);   Myjdbctest.displayresults (myresults);//Close all open resources myresults.close (); Mystmt.close (); Myconn.close ();}}





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.