gpt4 book ai didi

java - 如何从一台服务器更新另一台服务器中的表

转载 作者:行者123 更新时间:2023-12-01 11:22:29 29 4
gpt4 key购买 nike

我有以下代码,用于在一台服务器上打开两个文件并将这些文件中的数据更新到另一台数据库服务器。我能够打开数据库连接,但是当我尝试更新数据库服务器上的一个表时,它给出的连接是只读的,无法更新表。不知道我哪里做错了。请帮我解决这个问题,错误如下: enter image description here

import java.io.*;
import java.sql.*;

public class tstnew
{

public static void main (String args[]) throws Exception
{

FileInputStream fin,fin1;
int k=0;
String line,line1,s,s1,g,g1,d,d1;
try
{

Class.forName ("oracle.jdbc.driver.OracleDriver");

//DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@192.168.195.38:1521:ROW1", "********", "********");
System.out.println("connected");
Statement stmt = conn.createStatement();

//fin = new FileInputStream ("C:/Users/BOT2/Desktop/OGL/MC_WIth_DATA_Files.txt");
System.out.println("1");
fin = new FileInputStream ("C:/Users/Administrator/Desktop/SetUp/MC_WIth_DATA_Files.txt");

fin1 = new FileInputStream ("C:/Users/Administrator/Desktop/SetUp/MC_With_Empty_Files.txt");


DataInputStream in1 = new DataInputStream(fin);

BufferedReader br1 = new BufferedReader(new InputStreamReader(fin));
System.out.println("1");
BufferedReader br2= new BufferedReader(new InputStreamReader(fin1));

while ((line=br1.readLine() )!= null){
k++;
s=line.replaceAll("[0-9_]+", "");

g=s.replaceAll("\\s+","");

if(g.equals("Baltic")){g="Baltics";}
if(g.equals("Netherlands")){g="Netherland";}
if(g.equals("SouthAfricaSubSahara")){g="SSA";}
if(g.equals("Algeria")){g="ALGERIA";}
if(g.equals("EmergingMENA")){g="EMM";}
if(g.equals("SaudiArabia")){g="Saudi Arabia";}
if(g.equals("SouthAfrica")){g="South Africa";}
if(g.equals("Slovakia")){g="slovakia";}

System.out.println(g);

d="update ogl_table_status set status = 1 where mc_name='"+ g +"' and status=0";
stmt.executeUpdate(d);

}


while ( (line1=br2.readLine() )!= null ){
k++;

s1=line1.replaceAll("[0-9_]+", "");


g1=s1.replaceAll("\\s+","");


if(g1.equals("Baltic")){g1="Baltics";}
if(g1.equals("Netherlands")){g1="Netherland";}
if(g1.equals("SouthAfricaSubSahara")){g1="SSA";}
if(g1.equals("Algeria")){g1="ALGERIA";}
if(g1.equals("EmergingMENA")){g1="EMM";}
if(g1.equals("SaudiArabia")){g1="Saudi Arabia";}
if(g1.equals("SouthAfrica")){g1="South Africa";}
if(g1.equals("Slovakia")){g1="slovakia";}

System.out.println(g1);

d1="update ogl_table_status set status = 1 where mc_name='"+ g1 +"' and status=0";

stmt.executeUpdate(d1);

}
conn.commit();
System.out.println(k);
stmt.close();
br1.close();
br2.close();
fin.close();
fin1.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to read from file");
System.exit(-1);

}
}
}

最佳答案

错误提示:

database open for read only access

目前您可以执行 SELECT 语句以外的语句。您需要像前面那样以写入模式打开 Oracle DB this article为了执行UPDATE语句

关于java - 如何从一台服务器更新另一台服务器中的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31074402/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com