?? script_83.txt
字號:
---------- bash_profile_bak.txt ----------
/*
* 范例名稱:本機的環(huán)境變量
* 文件名稱: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 測試程序
* 運行時輸入連接信息,程序從數(shù)據(jù)庫中 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: ");
//必須輸入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 ();
// 從數(shù)據(jù)庫中 select出 "Hello World"
ResultSet rset = stmt.executeQuery ("select 'Hello World' from dual");
//如同cursor的fetch,其反值為false,如果已指向最后一條紀(jì)錄以后
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插入數(shù)據(jù)
* 文件名稱:InsertExample.java
*/
// This sample shows how to insert data in a table.
//向scott.emp表插入數(shù)據(jù)
// 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刪除原有數(shù)據(jù)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數(shù)據(jù)
pstmt.execute ();
// Close the statement
pstmt.close();
// Close the connecion
conn.close();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -