1. java如何操作資料庫之間的切換
//此類為連接資料庫並進行資料庫的操作
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conn {
private static Connection conn = null;
private static Statement st = null;
private static ResultSet rs = null;
//建立資料庫的連接
public Conn(){
String url = "jdbc:sqlserver://localhost:1433;databaseName=ZYGX";
String user = "sa";
String password = "123";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url, user, password);
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
// 通過不同 的sql語句,得到相應Resultset結果集
public ResultSet getRs(String sql){
try{
rs= st.executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
}
return rs;
}
// 根據不同的sql語句,執行資料庫的更新操作
public int updata(String sql){
int num=0;
try{
num = st.executeUpdate(sql);
}catch(SQLException e){
e.printStackTrace();
}
return num;
}
// 關閉資料庫連接相應的資源
public void close(){
try{
if(rs!=null){
rs.close();
rs = null;
}
if(st!=null){
st.close();
st = null;
}
if(conn!=null){
conn.close();
conn = null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
----------------------------------------------------------------------
//可以對button里添加動作按鈕:
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
Conn conn =new Conn();
String sql1="select * from aa where name='"+name+"' ";//按name值查找
ResultSet rs = conn.getRs(sql1);
try {
while(rs.next()){
int n=rs.getString("type");
}
} catch (SQLException e) {
e.printStackTrace();
}
String name=textField.getText();
String sql="update aa set tittle='"+name+"' ";//從aa表將title欄位的值改成textField里的name值
String sql2 ="delete from aa where name='"+name+"'";//從aa表將按取得name的值刪除該行數據
String sql3 = "insert into aa (name,uname) values ('"+name+"','"')"; //將name,uname值新增到aa表
if(conn.update(sql)==1){
System.out.print("修改成功");
}
if(conn.update(sql2)==1){
System.out.print("刪除成功");
}
if(conn.update(sql3)==1){
System.out.print("新增成功");
}
}
});
2. oracle資料庫如何切換模式
oracle dg 三大模式切換
1、最大性能模式MAXIMUM PERFORMANCE --默認模式,最大性能模式特點。
192.168.1.181
SQL>selectdatabase_role,protection_mode,protection_levelfromv$database;
DATABASE_ROLEPROTECTION_MODEPROTECTION_LEVEL
--------------------------------------------------------
SQL>coldest_namefora25
SQL>selectdest_name,statusfromv$archive_dest_status;
DEST_NAMESTATUS
----------------------------------
LOG_ARCHIVE_DEST_1VALID
LOG_ARCHIVE_DEST_2VALID
SQL>showparameterlog_archive
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_configstringdg_config=(orcl,db01)
log_archive_dest_1stringlocation=/home/oracle/arch_orc
lvalid_for=(all_logfiles,all_
roles)db_unique_name=orcl
log_archive_dest_2stringservice=db_db01LGWRASYNCval
id_for=(online_logfiles,primar
y_roles)db_unique_name=db01
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence31
Nextlogsequencetoarchive33
Currentlogsequence33
192.168.1.183
SQL>selectdatabase_role,protection_mode,protection_levelfromv$database;
DATABASE_ROLEPROTECTION_MODEPROTECTION_LEVEL
--------------------------------------------------------
SQL>coldest_namefora25
SQL>selectdest_name,statusfromv$archive_dest_status;
DEST_NAMESTATUS
----------------------------------
LOG_ARCHIVE_DEST_1VALID
LOG_ARCHIVE_DEST_2VALID
SQL>showparameterlog_archive
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_configstringdg_config=(db01,orcl)
log_archive_dest_1stringlocation=/home/oracle/arch_db0
1valid_for=(all_logfiles,all_
roles)db_unique_name=db01
log_archive_dest_2stringservice=db_orclLGWRASYNCval
id_for=(online_logfiles,primar
y_roles)db_unique_name=orcl
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence31
Nextlogsequencetoarchive33
Currentlogsequence33
192.168.1.181
SQL>altersystemswitchlogfile;
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence32
Nextlogsequencetoarchive34
Currentlogsequence34
192.168.1.183
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_db01
Oldestonlinelogsequence32
Nextlogsequencetoarchive0
Currentlogsequence34
2 、最大性能模式--切換到-->最大高可用 (默認是最大性能模式---MAXIMUM PERFORMANCE)。
192.168.1.181
SQL>selectDATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVELfromv$database;
DATABASE_ROLEPROTECTION_MODEPROTECTION_LEVEL
--------------------------------------------------------
SQL>showparameterlog_archive_dest_2
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_dest_2stringservice=db_db01LGWRASYNCval
id_for=(online_logfiles,primar
y_roles)db_unique_name=db01
192.168.1.181
SQL>shutdownimmediate
192.168.1.183
SQL>;
SQL>shutdownimmediate
192.168.1.181
SQL>startupmount;
SQL>;
SQL>altersystemsetlog_archive_dest_2='service=db_db01LGWRSYNCvalid_for=(online_logfiles,primary_roles)db_unique_name=db01'scope=spfile;
192.168.1.183
SQL>startupnomount
SQL>;
SQL>altersystemsetlog_archive_dest_2='service=db_orclLGWRSYNCvalid_for=(online_logfiles,primary_roles)db_unique_name=orcl'scope=spfile;
SQL>shutdownimmediate
SQL>startupnomount
SQL>;
192.168.1.181
SQL>startup
SQL>coldest_namefora25
SQL>selectdest_name,statusfromv$archive_dest_status;
DEST_NAMESTATUS
----------------------------------
LOG_ARCHIVE_DEST_1VALID
LOG_ARCHIVE_DEST_2VALID
SQL>showparameterlog_archive_dest_2
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_dest_2stringservice=db_db01LGWRSYNCvali
d_for=(online_logfiles,primary
_roles)db_unique_name=db01
SQL>selectdatabase_role,protection_level,protection_modefromv$database;
DATABASE_ROLEPROTECTION_LEVELPROTECTION_MODE
--------------------------------------------------------
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence34
Nextlogsequencetoarchive36
Currentlogsequence36
192.168.1.183
SQL>coldest_namefora25
SQL>selectdest_name,statusfromv$archive_dest_status;
DEST_NAMESTATUS
----------------------------------
LOG_ARCHIVE_DEST_1VALID
LOG_ARCHIVE_DEST_2VALID
SQL>showparameterlog_archive_dest_2
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_dest_2stringservice=db_orclLGWRSYNCvali
d_for=(online_logfiles,primary
_roles)db_unique_name=orcl
SQL>selectdatabase_role,protection_level,protection_modefromv$database;
DATABASE_ROLEPROTECTION_LEVELPROTECTION_MODE
--------------------------------------------------------
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_db01
Oldestonlinelogsequence35
Nextlogsequencetoarchive0
Currentlogsequence36
192.168.1.181
SQL>altersystemswitchlogfile;
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence35
Nextlogsequencetoarchive37
Currentlogsequence37
192.168.1.183
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_db01
Oldestonlinelogsequence36
Nextlogsequencetoarchive0
Currentlogsequence37
3、最大高可用--切換到-->最保護能模式,DG最大保護模式Maximum protection。
192.168.1.181
SQL>shutdownimmediate
192.168.1.183
SQL>shutdownimmediate
192.168.1.181
SQL>;
SQL>shutdownimmediate
192.168.1.183
SQL>startupnomount
SQL>;
192.168.1.181
SQL>startup
SQL>coldest_namefora25
SQL>selectdest_name,statusfromv$archive_dest_status;
DEST_NAMESTATUS
----------------------------------
LOG_ARCHIVE_DEST_1VALID
LOG_ARCHIVE_DEST_2VALID
SQL>showparameterlog_archive_dest_2
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_dest_2stringservice=db_db01LGWRSYNCvali
d_for=(online_logfiles,primary
_roles)db_unique_name=db01
SQL>selectdatabase_role,protection_level,protection_modefromv$database;
DATABASE_ROLEPROTECTION_LEVELPROTECTION_MODE
--------------------------------------------------------
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence37
Nextlogsequencetoarchive39
Currentlogsequence39
192.168.1.183
SQL>coldest_namefora25
SQL>selectdest_name,statusfromv$archive_dest_status;
DEST_NAMESTATUS
----------------------------------
LOG_ARCHIVE_DEST_1VALID
LOG_ARCHIVE_DEST_2VALID
SQL>showparameterlog_archive_dest_2
NAMETYPEVALUE
--------------------------------------------------------------------------
log_archive_dest_2stringservice=db_db01LGWRSYNCvali
d_for=(online_logfiles,primary
_roles)db_unique_name=db01
SQL>selectdatabase_role,protection_level,protection_modefromv$database;
DATABASE_ROLEPROTECTION_LEVELPROTECTION_MODE
--------------------------------------------------------
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_db01
Oldestonlinelogsequence37
Nextlogsequencetoarchive0
Currentlogsequence39
192.168.1.181
SQL>altersystemswitchlogfile;
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_orcl
Oldestonlinelogsequence38
Nextlogsequencetoarchive40
Currentlogsequence40
192.168.1.183
SQL>archiveloglist
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
Archivedestination/home/oracle/arch_db01
Oldestonlinelogsequence37
Nextlogsequencetoarchive0
Currentlogsequence40
3. mysql主備切換是什麼意思
這一般是資料庫的安全策略,對於一些安全性要求比較高的系統,資料庫通常是由主伺服器和備份伺服器組成,主備同時運行,主伺服器有數據改動後,立刻會同步到備份伺服器。所以在日常運維工作中,為了防患於未然,經常會進行主備切換,就是把生產對接的伺服器從主資料庫切換到備份庫上,使用備份庫運行一段時間,看看備份庫運行是否正常,數據是否正確等。
切換的操作只需將連接池中,資料庫伺服器的Ip換成備份庫Ip就可以了。
4. sql用什麼語句切換當前資料庫呢
--1、切換資料庫語句:
useAAADB;
go;
一般在程序中不使用以上語句
在程序內一般都是直接跨庫訪問,但首先當前資料庫用戶具備對別的數據有相應許可權,例如:
select*fromAAADB.dbo.AAA
以上語句是不管在當前在哪個資料庫下,都可以直接查詢AAADB資料庫下的AAA表,其中dbo是架構名
5. 程序如何在一台電腦上兩個資料庫之間切換
在連接的時候資料庫的時候選擇一下,根據不同選擇調用不同連接字元串就行了。
6. 我的Oracle中創建了多個資料庫,我應該如何在資料庫之間進行切換呢
你只需要在登陸的時候選擇哪個資料庫登陸就行了,前提是每個資料庫的所有服務都已經啟動。每個資料庫不是都有個什麼系統標識符啊,就那個,登陸格式你去找找哈,
7. ORACLE如何切換到用戶需要的資料庫
1、使用組合鍵「Win + R」打開運行對話框,在輸入框中輸入regedit 並回車打開「注冊表編輯器」。
8. 中英文資料庫連接切換
你把資料庫連接字元串當成一個變數來處理不就可以了嗎? if(language.equals("chinese")){url = ""}else{url=""}...再配置文件里的改變配置文件里的標識就可以
9. oracle 切換資料庫
直接登錄相應的用戶就可以了。
步驟:直接在命令行輸入sql>conn username/password;即可完成切換.
解釋:每個用戶都只能默認一個資料庫,不可能出現多個資料庫。所以直接切換到需要的用戶下即可完成操作。
10. 1.建立資料庫之前需要將當前資料庫切換到哪個資料庫
你說錯了吧,是用戶吧,要使用 system 用戶,才有許可權創建新用戶,創建表空間,授權。
然後登陸新用戶,做數據導入或者創建表等