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

📄 script_83.txt

📁 orale培训教材包括了所有的sql说明和实例
💻 TXT
字号:

---------- bash_profile_bak.txt ----------
/*
 * 范例名称:本机的环境变量
 * 文件名称:bash_profile_bak.txt
 */

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# Oracle env
if [ -f /etc/shell-mods.sh ]; then
	. /etc/shell-mods.sh
fi

# User specific environment and startup programs

JAVA_HOME=/usr/jdk
export JAVA_HOME
CATALINA_HOME=/usr/local/tomcat
export CATALINA_HOME
PATH=$PATH:$HOME/bin:/usr/jdk/bin
BASH_ENV=$HOME/.bashrc

export BASH_ENV PATH
unset USERNAME
CLASSPATH=.:$ORACLE_HOME/jdbc/lib/classes12.zip ; export CLASSPATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH


  
---------- JdbcCheckup.java ----------
/*
 * 范例名称:测试JDBC
 * 文件名称:JdbcCheckup.java
 */

/*
 * JDBC 测试程序
 * 运行时输入连接信息,程序从数据库中 select出
 * "Hello World" 
 */

// 必须 import java.sql package 以使用 JDBC
import java.sql.*;

// We import java.io to be able to read from the command line
import java.io.*;

class JdbcCheckup
{
  public static void main (String args [])
       throws SQLException, IOException
  {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // 提示 user 输入 connect information
    System.out.println ("Please enter information to test connection to the database");
    String user;
    String password;
    String database;
    
    //读取user输入,不是jdbc的重点。
    user = readEntry ("user: ");
    int slash_index = user.indexOf ('/');
    if (slash_index != -1)
    {
      password = user.substring (slash_index + 1);
      user = user.substring (0, slash_index);
    }
    else
      password = readEntry ("password: ");
    database = readEntry ("database (a TNSNAME entry): ");
    //必须输入TNSNAME

    System.out.print ("Connecting to the database...");
    System.out.flush ();

    System.out.println ("Connecting...");

    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:oci8:@" + database,
           user, password);
      //建立连接

    System.out.println ("connected.");

    // 建立statement对象
    Statement stmt = conn.createStatement ();

    // 从数据库中 select出 "Hello World" 
    ResultSet rset = stmt.executeQuery ("select 'Hello World' from dual");

    //如同cursor的fetch,其反值为false,如果已指向最后一条纪录以后
    while (rset.next ())
      System.out.println (rset.getString (1));
      //因为select 的字段为char,所以用.getString 方法

    System.out.println ("Your JDBC installation is correct.");

    // close the resultSet
    rset.close();

    // Close the statement
    stmt.close();

    // Close the connection
    conn.close();
  }

  // 用于从standard input读入一行,确保读如正确
  static String readEntry (String prompt)
  {
    try
    {
      StringBuffer buffer = new StringBuffer ();
      System.out.print (prompt);
      System.out.flush ();
      int c = System.in.read ();
      while (c != '\n' && c != -1)
      {
        buffer.append ((char)c);
        c = System.in.read ();
      }
      return buffer.toString ().trim ();
    }
    catch (IOException e)
    {
      return "";
    }
  }
}




---------- InsertExample.java ----------
/*
 * 范例名称:用JDBC插入数据
 * 文件名称:InsertExample.java
 */


// This sample shows how to insert data in a table.
//向scott.emp表插入数据
 
// You need to import the java.sql package to use JDBC
import java.sql.*;

class InsertExample
{
  public static void main (String args [])
       throws SQLException
  {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:oci8:@ora8", "scott", "tiger");

    // 使用Statement对象,从emp table删除原有数据empno=1500,507 
    Statement stmt = conn.createStatement ();
    try
    {
      stmt.execute ("delete from EMP where EMPNO = 1500");
    }
    catch (SQLException e)
    {
      // 忽略出错处理
    }

    try
    {
      stmt.execute ("delete from EMP where EMPNO = 507");
    }
    catch (SQLException e)
    {
      // 忽略出错处理
    }

    // Close the statement
    stmt.close();

    // Prepare to insert new names in the EMP table
    PreparedStatement pstmt = 
      conn.prepareStatement ("insert into EMP (EMPNO, ENAME) values (?, ?)");

    // Add PETER as employee number 1500
    pstmt.setInt (1, 1500);          // 第一个?代表 EMPNO
    pstmt.setString (2, "PETER");   // 第二个?代表 ENAME
    // Do the insertion
    pstmt.execute ();

    // Add PETER2 as employee number 507
    pstmt.setInt (1, 507);           // 第一个?代表 EMPNO
    pstmt.setString (2, "PETER2");   // 第二个?代表 ENAME
    // insert数据
    pstmt.execute ();

    // Close the statement
    pstmt.close();

    // Close the connecion
    conn.close();

  }
}

⌨️ 快捷键说明

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