navi kumar

Ranch Hand
+ Follow
since May 10, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by navi kumar

Thanks for the reply.

Yes, i recoded it ...it is working fine now.
18 years ago
I tried this, but is of no use.. returning a NULLPOINTEREXCEPTION:
InputStreamReader is = new FileReader(file);
BufferedReader bf = new BufferedReader(is);
while((bf.readLine())!= null)
{
if(bf.readLine().endsWith("\n"))
{
bf.readLine().replaceAll("\n", "\r\n");
}
}
I think "\n" is not found and hence NULLPOINTEREXCEPTION as suffix in endsWith(String suffix) is null!!

Any suggestions???

Thanks,
Naveen
18 years ago
Hi Hill,

sorry for double post..a bit of desperation!!

Anyhow could you give me a sample java code for reading the file with BufferedReader and writing in windows format.

Me not so good with java...thanks for understanding the prob clearly.
18 years ago
Hi Hill,

Thanks for the nimble reply.

Well With the code I have above, I am able to get data from a text file in unix file system into a BLOB column in Oracle table.

But..the data is expected to be present in the BLOB with each line in text file as a new line. But alas! with the code I have, i am writing it as stream of bytes with line delimiter(a rectangular box) at end of each line.

The question now is, is it possible to write the data into BLOB with each line seperated by a end-of-line instead of line delimiter(rectangular box)??

Regarding the catch block: The above code was cut shorted... morever there are no run time errors with the code!!

Thanks,
Naveen
18 years ago
Hi,

I have a text file on UNIX file system. This text files contains some 5000 lines. Where each line represents a record in an Oracle Table.( basically i spooled a oracle table's data into this text file)

I have a java class that writes this text file into a BLOB column on oracle database.

As you know there are two modes: ASCII and BINARY.

Basically, ASCII mode should be used when end-of-line character translation is required. and Binary mode (a.k.a. image mode) should be used whenever no end-of-line translation is required.

I need end-of-line character. i.e, each record should be written in new line in the BLOB.

But with the code i have, i am doing it the other way.
for ex: the data in blob should be like
1|VA|ARTNVAFC|FALLS CHURCH|2|H2009|8A00746|8A00738|FALLS CHURCH||TESINC|RELEASED TO CONSTRUCTION|03/30/2004||139|28|0|0|0|0|0|0|167||827|DISTRIBUTION|112635|O|||||||
2|VA|ARTNVAFC|FALLS CHURCH|2|H2010|8A00746|8A00736|FALLS CHURCH||TESINC|RELEASED TO CONSTRUCTION|02/20/2004||178|0|0|0|0|0|0|0|178||1711|DISTRIBUTION|135843|O|||||||

JAVA PROGRAM: I am not including all the code.. these the snippet that uploads the BLOB file in oracle table with the file from UNIX file system. .

byte[] fileData=getFileData(fileName , filePath);
updateFileData(conn,fileName,fileData);
public byte[] getFileData(String fileName,String filePath)
{
// Returns the contents of the file in a byte array.
File file=null;
try
{
file=new File(filePath + fileName);
if (!file.exists())
{
logFileException(filePath + fileName + " does not exists in the directory /u22/extract/");
return null;
}
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
/* You cannot create an array using a long type. It needs to be an int type.
Before converting to an int type, check to ensure that file is not larger than Integer.MAX_VALUE.*/

// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
{
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length)
{
logFileException(filePath + fileName + " Could not completely read file ");
return null;
}
// Close the input stream and return bytes
is.close();
return bytes;

}
catch(Exception e)
{}
return null;
}

public boolean updateFileData(Connection conn , String fileName,byte[] fileData)
{
PreparedStatement pstmt = null;
ResultSet rs1=null;
java.sql.Blob tempBlob=null;
FileInputStream is;
java.io.OutputStream os;
try
{
String fileNameStr=fileName.toUpperCase() ;
fileNameStr=fileNameStr.replaceAll("'","''");
pstmt=conn.prepareStatement("select ATTACH_FILE_CONTENT FROM TABLE_ATTACHMENTS "
+" Where upper(ATTACH_NAME)='" + fileNameStr + "' for update ");
rs1 = pstmt.executeQuery();
while (rs1.next())
{
tempBlob=rs1.getBlob("ATTACH_FILE_CONTENT");
}
pstmt.close();
rs1.close();
os=((oracle.sql.BLOB)tempBlob).getBinaryOutputStream();
os.write(fileData);
os.flush();
os.close();

pstmt = conn.prepareStatement("UPDATE " + TABLE_ATTACHMENTS + " set UPDATED_BY='USER',ATTACH_FILE_CONTENT=?, UPDATED_DT=SYSDATE Where upper(ATTACH_NAME)=? ");
pstmt.setBlob(1,tempBlob);
pstmt.setString(2,fileName.toUpperCase());
pstmt.executeUpdate();
pstmt.close();
return true;

}
catch(Exception e)
{
e.printStackTrace();
log ("updateFileData() - file Name=" + fileName + " exception " + e.toString() );
try
{
pstmt.close();
rs1.close();
}
catch(Exception ex)
{ex.printStackTrace();}
}

finally{
try
{
if (rs1 != null) {rs1.close();}
if (pstmt != null) {pstmt.close();}
}
catch(Exception e)
{e.printStackTrace();}
}
return false;
}
the data in the blob with above code is like :

1|VA|ARTNVAFC|FALLS CHURCH|2|H2009|8A00746|8A00738|FALLS CHURCH||TESINC|RELEASED TO CONSTRUCTION|03/30/2004||139|28|0|0|0|0|0|0|167||827|DISTRIBUTION|112635|O|||||||with a line delimiter here 2|VA|ARTNVAFC|FALLS CHURCH|2|H2010|8A00746|8A00736|FALLS CHURCH||TESINC|RELEASED TO CONSTRUCTION|02/20/2004||178|0|0|0|0|0|0|0|178||1711|DISTRIBUTION|135843|O|||||||

Thanks a lot

Naveen
18 years ago
Dan, thanks for you reply

Can I give something like this:

String filePath = C:/dir/file.txt;

Regards,
Hi all,

Could someone help me!

I have a file called "FILE.txt" on my disk at c:/dir/FILE.txt

Now I want to upload this file into the following table.

Table NAME : ATTACHMENTS_TABLE

FILE_NAME varchar2(30)
FILE_CONTENT BLOB
ATTACHED_DT DATE

Can some one suggest how to get that file on my disk into the input Stream?

THanks for you help
Hi, I am doing it this way.

in the jsp:
html:button property="submitButton" value="Delete" onKlick="javascript : deleteRecord();chkRegion();"

in the javascript:
function deleteRecord()
{
with(document.SearchRecordForm)
{
var msg = "Are you sure you want to delete the selected MDU Records ?";
if (confirm(msg)){
method.value = "deleteRecord";
submit();}}}

function chkRegion()
{
with(document.SearchRecordForm){
var region1 = rcdRegion.value;
if(region1 == "MID-ATLANTIC")
{
alert("Please delete MID_ATLANTIC records in Mid Atl Manage.");
}
return;
}
}

in the action :
public ActionForward deleteRecord(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception
{
String region = daoObj.deleteRecord(id, streetName,streetNum,delRecds);
formObj.setRcdRegion(region);
// here i am trying to set the RcdRegion which I call in javascript fucntion checkRegion()
return mapping.findForward("showDetail");
}

But, when I do this..
ERROR: rcdRegion is undefined.

I understand this error is because, the rcdRegion is empty when the function checkRegion() is called.

Please let me know, if there is any way to call the function2 after the function1.

For ex: in my case:
html:button property="submitButton" value="Delete" on
Klick="javascript: deleteRecord(); chkRegion();"
// when the DELETE button is clicked, the function deleteRecord() should be called... go to the method and perform all the action as defined. The page is loaded again(as defined in the method). Now, call the function chkRegion(). By doing so, I can check if the rcdRegion is null or not!

I tried doing something like onreturn(). But it didnt work. I was not sure whether to use it or not!

Please Help!
Regards
18 years ago
Thanks for the reply Naseem,

But, for confirmation, Is that possible or completely NO!
18 years ago
Hi all,

I have a situation where, I am supposed to pass a value from method in action class to JSP.

For ex,

in a method called
public ActionForward deleteRecord(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception
{
String region = daoObj.deleteRecord(id, Name, phaseNum, delRecds);
// the daoObj.deleteRecord returns a string.
}
Now, I want to get this String (region) into my external javascript file(being included in JSP) for validation purposes.

Is it possible to do so? If yes, please let me know.

Regards
18 years ago
Thanks for your replies Merrill. I got it working now
18 years ago
Merrill,

ths second JSP2 is being added to the JSP. But, when i want to submit the form, that is click the existing "update" button present in the second jsp2. It performs no action. and displays nothing on console.
I tried specifying the mapping of this second jsp2 in struts.configfile. When I do so and click update button, the action should update the values in table and show the entire jsp with updated values.

But, it shows only second jsp.

Please help
18 years ago
actually the UPDATE action is part of jsp2
18 years ago
Hi Merrill,

It is fine now. I can see the headers and footers as they are included in jsp now.

The problem now is:

I have an update button on my screen, which when clicked should update the table with changed values and further display the same screen with the updated values. But , it is giving an error( Error in the sense, it is not displaying anything on the Console)
Just saying...THERE IS PROBLEM WITH YOUR REQUEST> PLEASE TRY AGAIN....this is general jsp message we get in your application when the action does not return anything... i guess the same is happening here. ...Dont Understand why? Any help??? please
18 years ago
those two correspond to Header and Footer of every screen in the application. It is mandate to have them on the screen
18 years ago