⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdbc_prepstmt.java

📁 jdbc 的实例源码
💻 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_prepstmt {  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_prepstmt URL userid password");         System.err.println("");         System.err.println("  Examples:");         System.err.println(           "  java jdbc_prepstmt jdbc:odbc:MSSQL javadb javadb");         System.err.println(           "  java jdbc_prepstmt 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 from the Connection      //      String sql = "INSERT INTO food " +                   "(product, price)" +                   "VALUES(?, ?)";      PreparedStatement pstmt = con.prepareStatement(sql);      pstmt.setString(1, "Strange Flavored Chicken");      pstmt.setDouble(2, 4.95);      pstmt.executeUpdate();      pstmt.close();      con.close();      System.out.println("Operation was successful.");    }    catch( Exception e ) {      System.out.println(e.getMessage());      e.printStackTrace();    }  }}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -