新聞中心
myeclipse連接oracle數(shù)據(jù)庫(kù)后增刪改查方法怎么寫,我只寫出了查詢!
package org.accp.myservlet.entity;
創(chuàng)新新互聯(lián),憑借十載的網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站經(jīng)驗(yàn),本著真心·誠(chéng)心服務(wù)的企業(yè)理念服務(wù)于成都中小企業(yè)設(shè)計(jì)網(wǎng)站有1000+案例。做網(wǎng)站建設(shè),選成都創(chuàng)新互聯(lián)。
import java.sql.*;
public class BaseDao {
//dbUrl數(shù)據(jù)庫(kù)連接串信息,其中“1521”為端口,“ora9”為sid
String dbUrl = "jdbc:oracle:thin:@localhost:1521:oracle";
//theUser為數(shù)據(jù)庫(kù)用戶名
String theUser = "root";
//thePw為數(shù)據(jù)庫(kù)密碼
String thePw = "root";
//幾個(gè)數(shù)據(jù)庫(kù)變量
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進(jìn)行查詢
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();
}
}
oracle的方法怎么寫
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;
java jdbc連接數(shù)據(jù)庫(kù) oracle的代碼實(shí)現(xiàn)增刪改查的方法怎么寫
修改和刪除,可以使用ResultSet直接修改,切換到編輯狀態(tài)就可以。。。。。。。
建議直接使用SQL去修改,特別是刪除,使用SQL很快捷
oracle的imp使用方法
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的所有對(duì)象被導(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)入。
擴(kuò)展資料
ORACLE數(shù)據(jù)庫(kù)有兩類備份方法。第一類為物理備份,該方法實(shí)現(xiàn)數(shù)據(jù)庫(kù)的完整恢復(fù),但數(shù)據(jù)庫(kù)必須運(yùn)行在歸擋模式下(業(yè)務(wù)數(shù)據(jù)庫(kù)在非歸擋模式下運(yùn)行),且需要極大的外部存儲(chǔ)設(shè)備,例如磁帶庫(kù)。
第二類備份方式為邏輯備份,業(yè)務(wù)數(shù)據(jù)庫(kù)采用此種方式,此方法不需要數(shù)據(jù)庫(kù)運(yùn)行在歸擋模式下,不但備份簡(jiǎn)單,而且可以不需要外部存儲(chǔ)設(shè)備。
IMP常用選項(xiàng)
1、FROMUSER和TOUSER,使用它們實(shí)現(xiàn)將數(shù)據(jù)從一個(gè)SCHEMA中導(dǎo)入到另外一個(gè)SCHEMA中。例如:假設(shè)做exp時(shí)導(dǎo)出的為test的對(duì)象,現(xiàn)在想把對(duì)象導(dǎo)入用戶:imp?userid=test1/test1?file=expdat.dmp?fromuser=test1?touser=test1
2、IGNORE、GRANTS和INDEXES,其中IGNORE參數(shù)將忽略表的存在,繼續(xù)導(dǎo)入,這個(gè)對(duì)于需要調(diào)整表的存儲(chǔ)參數(shù)時(shí)很有用,可以先根據(jù)實(shí)際情況用合理的存儲(chǔ)參數(shù)建好表,然后直接導(dǎo)入數(shù)據(jù)。
而GRANTS和INDEXES則表示是否導(dǎo)入授權(quán)和索引,如果想使用新的存儲(chǔ)參數(shù)重建索引,或者為了加快到入速度,可以考慮將INDEXES設(shè)為N,而GRANTS一般都是Y。例如:impuserid=test1/test1file=expdat.dmpfromuser=test1touser=test1indexes=N
oracle循環(huán)存儲(chǔ)過(guò)程方法怎么寫,每條數(shù)據(jù)不一樣
方法1:用游標(biāo)可以解決呀!給你個(gè)例子。
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:還有一種方法,定義一個(gè)表類型的記錄,將所有數(shù)據(jù)插入到這個(gè)表類型記錄集中,然后再一次性插入到表中。
網(wǎng)頁(yè)標(biāo)題:oracle方法怎么寫,oracle常用方法
標(biāo)題來(lái)源:http://www.dlmjj.cn/article/dseeojp.html