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 用户,才有权限创建新用户,创建表空间,授权。
然后登陆新用户,做数据导入或者创建表等