small prob in ignoring string want to skip 2nd value?

I have CONSTRAINT Adept_Usr_Login NOT NULL,
now i want NOT NULL , -- to be appened before this
Adept_Usr_Login will change is dynamic
here is what i tried.

FileReader inputstream = new FileReader("C:/Documents and Settings/vijendras/Desktop/sampleApplicationchngd.sql");
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.split( " ", 3 );

// if the line starts with 'create' and a 'view' follows it,
// then add a "--" to the beginning of the line
if( tokens[ 0 ].equalsIgnoreCase( "CONSTRAINT" ) &&
tokens[ 2 ].equalsIgnoreCase( "NOT" ) &&
tokens[ 3 ].equalsIgnoreCase( "NULL" ) )
dataLines.append( " NOT " ).append(" NULL ").append(" , ").append(" -- ");

dataLines.append( dataLine ).append( '
' );
System.out.println( "Executed");
}
rdr.close(); // close the file

// open the file for writing new data to it
BufferedWriter writer = new BufferedWriter(new FileWriter("C:/Documents and Settings/vijendras/Desktop/sampleApplicationchngd.sql"));

// write the new StringBuilder's data back to the file.
writer.write( dataLines.toString(), 0, dataLines.length() );
writer.close(); // close the file

Comments

  • : I have CONSTRAINT Adept_Usr_Login NOT NULL,
    : now i want NOT NULL , -- to be appened before this
    : Adept_Usr_Login will change is dynamic
    : here is what i tried.
    :
    : FileReader inputstream = new FileReader("C:/Documents and Settings/vijendras/Desktop/sampleApplicationchngd.sql");
    : 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.split( " ", 3 );
    :
    : // if the line starts with 'create' and a 'view' follows it,
    : // then add a "--" to the beginning of the line
    : if( tokens[ 0 ].equalsIgnoreCase( "CONSTRAINT" ) &&
    : tokens[ 2 ].equalsIgnoreCase( "NOT" ) &&
    : tokens[ 3 ].equalsIgnoreCase( "NULL" ) )
    : dataLines.append( " NOT " ).append(" NULL ").append(" , ").append(" -- ");
    :
    : dataLines.append( dataLine ).append( '
    ' );
    : System.out.println( "Executed");
    : }
    : rdr.close(); // close the file
    :
    : // open the file for writing new data to it
    : BufferedWriter writer = new BufferedWriter(new FileWriter("C:/Documents and Settings/vijendras/Desktop/sampleApplicationchngd.sql"));
    :
    : // write the new StringBuilder's data back to the file.
    : writer.write( dataLines.toString(), 0, dataLines.length() );
    : writer.close(); // close the file
    :
    :


    Hi i have found this working for standalone class but when i try to incorporate same in my application its not working what can be the possibilities.Before that whatever i tested which is not working for stanalone classes is not working for application.
    How can i think of solving such things.

    any guesses.

    code is here:

    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.split( " ", 3 );

    if(tokens[0].trim().equalsIgnoreCase("CONSTRAINT") && dataLine.endsWith("NOT NULL,") )
    {
    dataLines.append("NOT ").append("NULL").append(", ").append("--");
    dataLines.append(dataLine).append( '
    ' );
    System.out.println( "Executed");
    }
    else{
    dataLines.append(dataLine).append( '
    ' );
    }
    }

    i tested for possibilities like
    if(tokens[ 0 ].trim().equalsIgnoreCase( "CONSTRAINT") &&
    tokens[ 2 ].trim().equalsIgnoreCase( "NOT NULL," ) )

    if( tokens[ 0 ].equalsIgnoreCase( "CONSTRAINT") && tokens[ 2 ].equalsIgnoreCase( "NOT") &&
    tokens[ 3 ].equalsIgnoreCase( "NULL," ) )

    Please let me know any other possibilities left.
    I have spend three days only 1st one worked but no one for my application is giving desired results.

    thanks
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion