data modification code not working please suggest something good?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vijendra_Singh
Posted On:   Monday, July 3, 2006 03:46 AM

Hi all, I have a sql file where for all "CONSTRAINT anyname NOT NULL," occurences i have to append "NOT NULL, -- " before "CONSTRAINT Adept_Usr_Login NOT NULL," in order to modify that. I have written this code which is not giving required result. Please provide me some better solution if someone can. The sql file contents are: CREATE TABLE Adept_User( Id NUMBER(10, 0) NOT NULL, Login_Name VARCHAR2(30) CONSTRAINT Adept_Usr_Login NOT NULL, First_Name VARCHAR2(35) CONSTRAINT Adept_Usr_First_name NOT NULL, Last_Name VARCHAR2(35), User_Password VARCHAR2(10) CONSTRAINT Adept_Usr_Last_name NOT NULL,    More>>

Hi all,
I have a sql file where for all "CONSTRAINT anyname NOT NULL," occurences i have to append "NOT NULL, -- " before "CONSTRAINT Adept_Usr_Login NOT NULL," in order to modify that.
I have written this code which is not giving required result. Please provide me some better solution if someone can. The sql file contents are:


CREATE TABLE Adept_User(

Id NUMBER(10, 0) NOT NULL,

Login_Name VARCHAR2(30)

CONSTRAINT Adept_Usr_Login NOT NULL,

First_Name VARCHAR2(35)

CONSTRAINT Adept_Usr_First_name NOT NULL,

Last_Name VARCHAR2(35),

User_Password VARCHAR2(10)

CONSTRAINT Adept_Usr_Last_name NOT NULL,

User_Status NUMBER(10, 0)

CONSTRAINT Adept_Usr_Status NOT NULL,

User_Type NUMBER(10, 0)

CONSTRAINT Adept_Usr_Type NOT NULL,

Customer_Contact NUMBER(10, 0),

Employee NUMBER(10, 0),

Organization Number(10,0),

Password_Modified_Date DATE,

Currency_Master_Id NUMBER(10, 0),

CONSTRAINT PK23 PRIMARY KEY (Id)

)

;

CREATE TABLE Adept_User_Group(

Id NUMBER(10, 0) NOT NULL,

Adept_Group NUMBER(10, 0)

CONSTRAINT Adept_Usr_Grp NOT NULL,

Adept_User_Name NUMBER(10, 0)

CONSTRAINT Adept_Usr_name NOT NULL,

CONSTRAINT PK157 PRIMARY KEY (Id)

)

;



CREATE TABLE Adept_User_Permission(

Id NUMBER(10, 0) NOT NULL,

Adept_Screens NUMBER(10, 0)

CONSTRAINT Adept_Usr_Perm_Scren NOT NULL,

Adept_User_Group NUMBER(10, 0)

CONSTRAINT Adept_Usr_Grp NOT NULL,

Dashboard char(1),

CONSTRAINT PK28 PRIMARY KEY (Id)

)

;





The code written is:



import java.io.*;

class MySample1

{

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

{

String file="C:/Documents and

Settings/vijendras/Desktop/sampleApplicationchngd.sql";

FileReader inputstream = new FileReader(file);

BufferedReader rdr = new BufferedReader( inputstream );



// the StringBuilder which stores the processed lines

StringBuffer dataLines = new StringBuffer();

// read the file line by line

String dataLine;

while( ( dataLine = rdr.readLine() ) != null ) {

// split the input data into words upto first 3 words only

String[] tokens = dataLine.trim().split( " ",3 );



if( tokens[ 0 ].trim().equalsIgnoreCase( "CONSTRAINT") && tokens[ 2

].trim().equalsIgnoreCase( "NOT") &&

tokens[ 3 ].trim().equalsIgnoreCase( "NULL," ) )

{

dataLines.append( "NOT" ).append(" NULL").append(",").append(" -- ");

System.out.println(dataLines.toString());

}

else{

dataLines.append(dataLine).append( '
' );

}



}

rdr.close(); // close the file

// open the file for writing new data to it

BufferedWriter writer = new BufferedWriter(new

FileWriter(file));

//System.out.println(dataLines.toString());

// write the new StringBuilder's data back to the file.

writer.write( dataLines.toString(), 0, dataLines.length()

);

writer.close(); // close the filev

}

}





Thanks

Vijendra

   <<Less

Re: data modification code not working please suggest something good?

Posted By:   WarnerJan_Veldhuis  
Posted On:   Monday, July 3, 2006 03:56 AM

About | Sitemap | Contact