?? sample.java
字號:
/** * sample - a sample MsqlJava client. * * @author Brian Jepson * @author Copyright 1996, John Wiley and Sons * * 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 msql.*;public class sample { /** * main() - the main method * * @param argv[0] name of mSQL host (default == localhost) * */ public static void main(String argv[]) { // instantiate an Msql object... Msql msql = new Msql(); // a hostname can be specified on the command line String host; if (argv.length > 0) { host = argv[0]; } else { // if no hostname was specified, use localhost host = "localhost"; } try { // make a connection to the specified host, // and select the sample database msql.Connect(host); msql.SelectDB("sample"); // if the "sample_table" already exists, drop it // we can determine if the table exists by iterating // over the output of ListTables() String[] tables = msql.ListTables(); if (tables != null) { for (int i = 0; i < tables.length; i++) { if (tables[i].equals("sample_table")) { msql.Query("drop table sample_table"); } } } // create the "sample_table" table msql.Query("create table sample_table (name char(15))"); // insert a few values into it msql.Query("insert into sample_table (name) values ('Brian')"); msql.Query("insert into sample_table (name) values ('Christopher')"); msql.Query("insert into sample_table (name) values ('David')"); msql.Query("insert into sample_table (name) values ('Michael')"); msql.Query("insert into sample_table (name) values ('Nathan')"); msql.Query("insert into sample_table (name) values ('Ron')"); // retrieve all of the rows from it MsqlResult result = msql.Query("select name from sample_table"); // fetch each row from the results, and print out // the first column. FetchRow returns an array of // strings, which positionally correspond to the // columns in the result set. String row[]; while(( row = result.FetchRow()) != null) { System.out.println("[" + row[0] + "]"); } } // print a stack trace if we catch an exception catch(MsqlException e ) { e.printStackTrace(); } } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -