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

时间:2015-06-26 13:25:30

标签: java plsql

我有以下代码,用于在一台服务器上打开两个文件,并将这些文件中的数据更新到另一台数据库服务器。我能够打开数据库连接但是当我尝试更新数据库服务器上的一个表时,它提供的连接只读取无法更新表。不知道我做错了什么。请帮帮我,错误如下: 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);

        }
    }   
}

1 个答案:

答案 0 :(得分:1)

错误说:

  

数据库打开以进行只读访问

目前,您可以执行SELECT语句以外的其他语句。 您需要以WRITE模式打开Oracle DB作为前this article才能执行UPDATE语句