?? jdbc_multi.java
字號:
/* * Copyright 1996 John Wiley & Sons, Inc. All Rights Reserved. Reproduction * or translation of this work beyond that permitted in Section 117 of the 1976 * United States Copyright Act without the express written permission of the * copyright owner is unlawful. Requests for further information should be * addressed to Permissions Department, John Wiley & Sons, Inc. The * purchaser may make back-up copies for his/her own use only and not for * distribution or resale. The Publisher assumes no responsibility for errors, * omissions, or damages, caused by the use of this software or from the use * of the information contained herein. * */import java.net.URL;import java.sql.*;class jdbc_multi { public static void main(String argv[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); // JDBC-ODBC bridge Class.forName("com.sybase.jdbc.SybDriver").newInstance(); // Sybase } catch (Exception e) { e.printStackTrace(); } try { // the url, userid, and password come in from argv, so error out if // they weren't passed. // if (argv.length < 3) { System.err.println("Usage:"); System.err.println(""); System.err.println("java jdbc_multi URL userid password"); System.err.println(""); System.err.println(" Examples:"); System.err.println( " java jdbc_multi jdbc:odbc:MSSQL javadb javadb"); System.err.println( " java jdbc_multi jdbc:sybase:Tds:localhost:4000 javadb javadb"); System.exit(0); } String url = argv[0]; String user = argv[1]; String pwd = argv[2]; // make a connection to the specified URL // Connection con = DriverManager.getConnection(url, user, pwd); // get a statement object // Statement stmt = con.createStatement(); // execute a stored procedure // stmt.execute("{call multi_sample}"); // get the first result set // ResultSet rs = stmt.getResultSet(); // if the first result set wasn't null, // the program should try to get the next // result set // boolean more_results; if (rs != null) { more_results = true; } else { more_results = false; } // keep getting results until there are no more // result sets to process // while(more_results) { // get each row and print it // boolean seen = false; while( rs.next() ) { String product = rs.getString(1); if (!seen) { System.out.println("ALL THE " + rs.getString(2) + "S."); } System.out.println(" " + product); seen = true; } // try to get another result set // more_results = stmt.getMoreResults(); if (more_results) { rs = stmt.getResultSet(); } } stmt.close(); con.close(); } catch( Exception e ) { System.out.println(e.getMessage()); e.printStackTrace(); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -