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 ();}}