十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
package org.accp.myservlet.entity;
創(chuàng)新新互聯(lián),憑借十載的網(wǎng)站設(shè)計、成都做網(wǎng)站經(jīng)驗,本著真心·誠心服務(wù)的企業(yè)理念服務(wù)于成都中小企業(yè)設(shè)計網(wǎng)站有1000+案例。做網(wǎng)站建設(shè),選成都創(chuàng)新互聯(lián)。
import java.sql.*;
public class BaseDao {
//dbUrl數(shù)據(jù)庫連接串信息,其中“1521”為端口,“ora9”為sid
String dbUrl = "jdbc:oracle:thin:@localhost:1521:oracle";
//theUser為數(shù)據(jù)庫用戶名
String theUser = "root";
//thePw為數(shù)據(jù)庫密碼
String thePw = "root";
//幾個數(shù)據(jù)庫變量
Connection c = null;
Statement conn;
ResultSet rs = null;
//初始化連接
public BaseDao() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
//與url指定的數(shù)據(jù)源建立連接
c = DriverManager.getConnection(dbUrl, theUser, thePw);
//采用Statement進行查詢
conn = c.createStatement();
} catch (Exception e) {
e.printStackTrace();
}
}
//執(zhí)行查詢
public ResultSet executeQuery(String sql) throws SQLException {
rs = null;
try {
rs = conn.executeQuery(sql);
} catch (Exception e) {
e.printStackTrace();
} finally{
close();
}
return rs;
}
//執(zhí)行修改
public void update(String sql) throws SQLException{
int len = 0;
try {
len = conn.executeUpdate(sql);
if(len0){
System.out.println("修改成功");
}else{
System.out.println("修改失敗");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close();
}
}
//執(zhí)行添加
public void Add(String sql) throws SQLException{
boolean bool = false;
try {
bool = conn.execute(sql);
if(bool){
System.out.println("添加成功");
}else{
System.out.println("添加失敗");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close();
}
}
//執(zhí)行刪除
public void Delet(String sql) throws SQLException{
boolean bool = false;
try {
bool = conn.execute(sql);
if(bool){
System.out.println("刪除成功");
}else{
System.out.println("刪除失敗");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
close();
}
}
public void close() {
try {
conn.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException {
ResultSet newrs;
BaseDao newjdbc = new BaseDao();
newrs = newjdbc.executeQuery("select * from users");
try {
while (newrs.next()) {
System.out.print(newrs.getString("USERID"));
System.out.print(":"+newrs.getString("USERNAME"));
System.out.print(":"+newrs.getString("PASSWB"));
System.out.print(":"+newrs.getString("EMAIL"));
System.out.println(":"+newrs.getString("GRADE"));
}
} catch (Exception e) {
e.printStackTrace();
}
newjdbc.close();
}
}
01.CREATE OR REPLACE FUNCTION get_short_name(p_username VARCHAR2) RETURN VARCHAR2 IS
02.v_username VARCHAR2(1000);
03.
04.BEGIN
05.v_username := p_username;
06.
07.IF INSTR(v_username, 'TenGigabitEthernet') 0 THEN
08.v_username := REPLACE(v_username, 'TenGigabitEthernet', 'TGE');
09.END IF;
10.
11.RETURN v_username;
12.
13.EXCEPTION
14.WHEN NO_DATA_FOUND THEN
15.return null;
16.WHEN OTHERS THEN
17.return null;
18.
19.END get_short_name;
修改和刪除,可以使用ResultSet直接修改,切換到編輯狀態(tài)就可以。。。。。。。
建議直接使用SQL去修改,特別是刪除,使用SQL很快捷
oracle的imp使用方法具有三種模式(完全、用戶、表)
1、完全:
IMP SYSTEM/MANAGER BUFFER=64000 FILE=C:\FULL.DMP FULL=Y
2、用戶模式:
IMP SONIC/SONIC??? BUFFER=64000 FILE=C:\SONIC.DMP FROMUSER=SONIC TOUSER=SONIC
這樣用戶SONIC的所有對象被導(dǎo)入到文件中。必須指定FROMUSER、TOUSER參數(shù),這樣才能導(dǎo)入數(shù)據(jù)。
3、表模式:
EXP SONIC/SONIC??? BUFFER=64000 FILE=C:\SONIC.DMP OWNER=SONIC TABLES=(SONIC)
這樣用戶SONIC的表SONIC就被導(dǎo)入。
擴展資料
ORACLE數(shù)據(jù)庫有兩類備份方法。第一類為物理備份,該方法實現(xiàn)數(shù)據(jù)庫的完整恢復(fù),但數(shù)據(jù)庫必須運行在歸擋模式下(業(yè)務(wù)數(shù)據(jù)庫在非歸擋模式下運行),且需要極大的外部存儲設(shè)備,例如磁帶庫。
第二類備份方式為邏輯備份,業(yè)務(wù)數(shù)據(jù)庫采用此種方式,此方法不需要數(shù)據(jù)庫運行在歸擋模式下,不但備份簡單,而且可以不需要外部存儲設(shè)備。
IMP常用選項
1、FROMUSER和TOUSER,使用它們實現(xiàn)將數(shù)據(jù)從一個SCHEMA中導(dǎo)入到另外一個SCHEMA中。例如:假設(shè)做exp時導(dǎo)出的為test的對象,現(xiàn)在想把對象導(dǎo)入用戶:imp?userid=test1/test1?file=expdat.dmp?fromuser=test1?touser=test1
2、IGNORE、GRANTS和INDEXES,其中IGNORE參數(shù)將忽略表的存在,繼續(xù)導(dǎo)入,這個對于需要調(diào)整表的存儲參數(shù)時很有用,可以先根據(jù)實際情況用合理的存儲參數(shù)建好表,然后直接導(dǎo)入數(shù)據(jù)。
而GRANTS和INDEXES則表示是否導(dǎo)入授權(quán)和索引,如果想使用新的存儲參數(shù)重建索引,或者為了加快到入速度,可以考慮將INDEXES設(shè)為N,而GRANTS一般都是Y。例如:impuserid=test1/test1file=expdat.dmpfromuser=test1touser=test1indexes=N
方法1:用游標(biāo)可以解決呀!給你個例子。
FOR c IN (SELECT DISTINCT wdd.organization_id,
wdd.ship_from_location_id,
wdd.ship_to_location_id,
wdd.customer_id,
wdd.freight_terms_code,
wdd.fob_code,
wdd.source_header_id,
wdd.source_header_type_id
FROM wsh_delivery_details wdd
WHERE wdd.released_status IN ('R', 'B')
AND wdd.inventory_item_id IN
(SELECT DISTINCT mln.inventory_item_id
FROM bs_edi_shipment_ge bes,
mtl_lot_numbers_all_v mln
WHERE mln.lot_number = bes.lot_number
AND bes.header_id = l_header_id)) LOOP
INSERT INTO Document VALUES(c.organization_id,
c.ship_from_location_id,
c.ship_to_location_id,
c.customer_id,
c.freight_terms_code,
c.fob_code,
c.source_header_id,
c.source_header_type_id);
END LOOP;
將游標(biāo)里面的數(shù)據(jù)一條一條的插入到你想插入到的表。
方法2:還有一種方法,定義一個表類型的記錄,將所有數(shù)據(jù)插入到這個表類型記錄集中,然后再一次性插入到表中。