Storing an uploaded file to the database is not as easy as just storing string information. Storing the attachment as just a physical file and other info such as path, file name, mimetype and size is much easier.
But how come, all these while uploading file was never an issue, only until recently? Clients complaint that whenever they upload a ".docx" file, error will occur. After some findings on the log file, the error is actually the mimetype size that I have set for the database table was insufficient. Mine was varchar(50), but yet insufficient. So how long do you actually need? As for me, I have increased my original varchar(50) to varchar(100).
Why this long? After reading this, you will know why. This is the problem with MS. I don't even know why they need it to be so long. Here's a list of office extension with its mimetype from the Net.
Extension MIMEType
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.sldx application/vnd.openxmlformats-officedocument.presentationml.slide
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
Showing posts with label MatrixCodeForDevelopers. Show all posts
Showing posts with label MatrixCodeForDevelopers. Show all posts
Tuesday, August 18, 2009
Dev : Download File With Semicolon
Created a spreadsheet, named as wifes_acc;children_acc.xls. Uploaded to an webapplication, and try to download it using IE7. WTF?! How come my spreadsheet became wifes_acc only after I click download. Where is there remaining name? How come the file was not found on the server?
Damn, what happened. Try with mozilla. Wow, it downloaded just fine. What happened?
We came across such problem when dealing with upload and download of attachment. After some finding on the Net, I realized that the actual problem lies with IE7. When ever user click the download button, we will execute "response.setHeader("xxxx")" on our coding to set the file name. In such, IE will always read the semicolon ";" in the header data as a delimiter for others parameters. Therefore, the name was actually splited into 2 parts.
Damn, an IE7 bug, hopefully such problem will be resolved in IE8.
Damn, what happened. Try with mozilla. Wow, it downloaded just fine. What happened?
We came across such problem when dealing with upload and download of attachment. After some finding on the Net, I realized that the actual problem lies with IE7. When ever user click the download button, we will execute "response.setHeader("xxxx")" on our coding to set the file name. In such, IE will always read the semicolon ";" in the header data as a delimiter for others parameters. Therefore, the name was actually splited into 2 parts.
Damn, an IE7 bug, hopefully such problem will be resolved in IE8.
Wednesday, July 08, 2009
Dev : Informix Inner Select
What if you are trying to create a virtual table for SQL?
As per standard database query, usually we would write something like:
SELECT some_fields FROM (SELECT selected_fields FROM table1) vtable
But in Informix, one of the much used relational database worldwide (but which I do not really like to use), had to be written in a slightly different way:
SELECT some_fields FROM TABLE(MULTISET(SELECT selected_fields FROM table1)) vtable
That's all. Not too much difference, but gosh, why on earth it has to be so complicating. Haha~~~
As per standard database query, usually we would write something like:
SELECT some_fields FROM (SELECT selected_fields FROM table1) vtable
But in Informix, one of the much used relational database worldwide (but which I do not really like to use), had to be written in a slightly different way:
SELECT some_fields FROM TABLE(MULTISET(SELECT selected_fields FROM table1)) vtable
That's all. Not too much difference, but gosh, why on earth it has to be so complicating. Haha~~~
Monday, June 01, 2009
Dev : Java Send Mail
Ever wonder why your application did not send the email out? Your code seems fine, but still fails. Single mail address is OK, but when coming to a list of emails, you're getting "550 5.1.1 User unknown" or some other error stating that one or more emails are not valid.
Well, this feature is actually intended by Sun. But I still want to send the email to the valid emails and how do we overcome this problem? Simple, by just added an extra line to the email property will do.
Normally, we would tell the mailserver what is the values for "mail.transport.protocol", "mail.smtp.host", "mail.host" and such, we just need to add in this "mail.smtp.sendpartial" and the value for it is true. With this, although the exception will still be thrown, but those with valid email will received the mail.
Of course, if you have cater for a resend if exception occurs, better check your code and list of emails. You would not want valid email owners keep on receiving the same mail over and over again. :)
Well, this feature is actually intended by Sun. But I still want to send the email to the valid emails and how do we overcome this problem? Simple, by just added an extra line to the email property will do.
Normally, we would tell the mailserver what is the values for "mail.transport.protocol", "mail.smtp.host", "mail.host" and such, we just need to add in this "mail.smtp.sendpartial" and the value for it is true. With this, although the exception will still be thrown, but those with valid email will received the mail.
Of course, if you have cater for a resend if exception occurs, better check your code and list of emails. You would not want valid email owners keep on receiving the same mail over and over again. :)
Tuesday, March 10, 2009
Dev : URL Extension
In your webpage, there is a hyperlink in your web is as such http://localhost:8080/webname/help.chm. You could not click it, as it will open as a garbage, alien language in your Internet Explorer. Have you come across with such problem?
No matter how I write the javascript, I can't manage to get it to "force" download using javascript. It will always open it as garbage. At last, I turn to my manager. He told me to use mime-mapping in web.xml.
After some research online, found that we can actually tell app server that such "extension" is a certain file type. As simple as 1-2-3, we just need to add these codes in the web.xml correctly. You might want to verify the placement.
<!-- set mime mapping for help file -->
<MIME-MAPPING>
<EXTENSION>chm</EXTENSION>
<MIME-TYPE>application/mshelp</MIME-TYPE>
</MIME-MAPPING>
Likewise, for other extension, we may put it as other mime-type, such as "application/pdf" for pdf, "application/vnd.ms-excel" for xls and others. You should be able to get the correct type by browsing the net.
After saving your web.xml, you just need to restart your app server and clear your temporary Internet file.
No matter how I write the javascript, I can't manage to get it to "force" download using javascript. It will always open it as garbage. At last, I turn to my manager. He told me to use mime-mapping in web.xml.
After some research online, found that we can actually tell app server that such "extension" is a certain file type. As simple as 1-2-3, we just need to add these codes in the web.xml correctly. You might want to verify the placement.
<!-- set mime mapping for help file -->
<MIME-MAPPING>
<EXTENSION>chm</EXTENSION>
<MIME-TYPE>application/mshelp</MIME-TYPE>
</MIME-MAPPING>
Likewise, for other extension, we may put it as other mime-type, such as "application/pdf" for pdf, "application/vnd.ms-excel" for xls and others. You should be able to get the correct type by browsing the net.
After saving your web.xml, you just need to restart your app server and clear your temporary Internet file.
Monday, November 24, 2008
Dev : MSSQL Server Case Sensitivity
Using database such as Oracle will insist that you use the correct case to do a select filter. But, if you use MSSQL 2000/2005, by default it is case-insensitive. You may need to choose it while in installation if I am not mistaken.
Thus, it means that:
select * from user where id = 'admin'
will always produce the same result as
select * from user where id = 'ADMIN'
if it is case_insensitive.
In this case, how would we make sure that our select statement always base on case sensitivity? Esspecially when comparing fields such as password where the case sensitivity is crucial?
Simple, just add 'COLLATE SQL_Latin1_General_CP1_CS_AS' at the end of the select statement to solve the matter.
Thus, by adding these words, it will always make sure that:
select * from user where id = 'admin' COLLATE SQL_Latin1_General_CP1_CS_AS
will always produce different result as
select * from user where id = 'ADMIN' COLLATE SQL_Latin1_General_CP1_CS_AS
If you want to ignore case sensitivity when by default is case-sensitive, then the SQL should be
select * from user where id = 'admin' COLLATE SQL_Latin1_General_CP1_CI_AS
Thus, it means that:
select * from user where id = 'admin'
will always produce the same result as
select * from user where id = 'ADMIN'
if it is case_insensitive.
In this case, how would we make sure that our select statement always base on case sensitivity? Esspecially when comparing fields such as password where the case sensitivity is crucial?
Simple, just add 'COLLATE SQL_Latin1_General_CP1_CS_AS' at the end of the select statement to solve the matter.
Thus, by adding these words, it will always make sure that:
select * from user where id = 'admin' COLLATE SQL_Latin1_General_CP1_CS_AS
will always produce different result as
select * from user where id = 'ADMIN' COLLATE SQL_Latin1_General_CP1_CS_AS
If you want to ignore case sensitivity when by default is case-sensitive, then the SQL should be
select * from user where id = 'admin' COLLATE SQL_Latin1_General_CP1_CI_AS
Thursday, November 13, 2008
Dev : Cannot find bean under name org.apache.struts.taglib.html.BEAN
I am getting this error - "Cannot find bean under name org.apache.struts.taglib.html.BEAN" when loading my jsp page. Something is wrong. What could it be?
At first, since it mentioned cannot find something, my thought was to check all my imported libraries. Nope, that wasn't the case. After some finding, finally I just realize that I have forgottten to put in the form name.
As for Struts framework's struts-html.tld to work properly in the page, we should always created the page as such:
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<html:form action="action_name_mapped_in_struts_config">
... some code...
</html:form>
This is to ensure that the correct naming and mapping is used when we are using struts-html tag.
At first, since it mentioned cannot find something, my thought was to check all my imported libraries. Nope, that wasn't the case. After some finding, finally I just realize that I have forgottten to put in the form name.
As for Struts framework's struts-html.tld to work properly in the page, we should always created the page as such:
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<html:form action="action_name_mapped_in_struts_config">
... some code...
</html:form>
This is to ensure that the correct naming and mapping is used when we are using struts-html tag.
Friday, August 15, 2008
Dev : MsSQL Drop Only If Exist
If you were to execute "DROP TABLE table1" or "ALTER TABLE table1 DROP COLUMN field1" in MsSQL server, probably you'll encouter error complaining the table or the column does not exist.
So how do you verify such table or column existed before you could drop them? There is a way. By querying the "INFORMATION_SCHEMA" table, you should be able to drop it without the concern of getting error.
Instead of "DROP TABLE table1", we can use
"if exists (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'table1')
DROP TABLE table1".
And instead of "ALTER TABLE table1 DROP COLUMN field1", we can use
"if exists (SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'table1'
and column_name = 'field1')
alter table table1
drop column field1".
So how do you verify such table or column existed before you could drop them? There is a way. By querying the "INFORMATION_SCHEMA" table, you should be able to drop it without the concern of getting error.
Instead of "DROP TABLE table1", we can use
"if exists (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'table1')
DROP TABLE table1".
And instead of "ALTER TABLE table1 DROP COLUMN field1", we can use
"if exists (SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'table1'
and column_name = 'field1')
alter table table1
drop column field1".
Wednesday, August 06, 2008
Dev : div vs span tag
Some of us may come across with the <div>and <span> tag before. What is the difference? Both usage seems almost the same.
Well, not exactly the same, but yes, almost. Both are elements of a document, but <div>is a block element and <span> is an inline element. And what is block and inline? Block elements take the whole section of a page, at least a whole full line, but inline will use as little space as possible, just like filling a gap.
DIV
I am <div>a</div>boy.
will produce
I am
yet,SPAN
I am <span>a</span> boy
will produce
I am a boy.
So, can you see the differences now?
Well, not exactly the same, but yes, almost. Both are elements of a document, but <div>is a block element and <span> is an inline element. And what is block and inline? Block elements take the whole section of a page, at least a whole full line, but inline will use as little space as possible, just like filling a gap.
DIV
I am <div>a</div>boy.
will produce
I am
a
boy.yet,SPAN
I am <span>a</span> boy
will produce
I am a boy.
So, can you see the differences now?
Wednesday, June 11, 2008
Dev : What is an abstract class
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
Let's look at the following example: Each animal sure has some common actions can be defined in abstract class, but we implement uncommon actions to be implemented in sub class.
public abstract Animal
{
public void eat(Food food)
{
// do something with food....
}
public void sleep(int hours)
{
try
{
// 1000 milliseconds * 60 seconds * 60 minutes * hours
Thread.sleep ( 1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) { /* ignore */ }
}
public abstract void makeNoise();
}
Let's look at a Dog and Cow subclass that extends the Animal class.
public Dog extends Animal
{
public void makeNoise() { System.out.println ("Bark! Bark!"); }
}
public Cow extends Animal
{
public void makeNoise() { System.out.println ("Moo! Moo!"); }
}
Now you may be wondering why not declare an abstract class as an interface, and have the Dog and Cow implement the interface. Sure you could - but you'd also need to implement the eat and sleep methods. By using abstract classes, you can inherit the implementation of other (non-abstract) methods. You can't do that with interfaces - an interface cannot provide any method implementations.
Let's look at the following example: Each animal sure has some common actions can be defined in abstract class, but we implement uncommon actions to be implemented in sub class.
public abstract Animal
{
public void eat(Food food)
{
// do something with food....
}
public void sleep(int hours)
{
try
{
// 1000 milliseconds * 60 seconds * 60 minutes * hours
Thread.sleep ( 1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) { /* ignore */ }
}
public abstract void makeNoise();
}
Let's look at a Dog and Cow subclass that extends the Animal class.
public Dog extends Animal
{
public void makeNoise() { System.out.println ("Bark! Bark!"); }
}
public Cow extends Animal
{
public void makeNoise() { System.out.println ("Moo! Moo!"); }
}
Now you may be wondering why not declare an abstract class as an interface, and have the Dog and Cow implement the interface. Sure you could - but you'd also need to implement the eat and sleep methods. By using abstract classes, you can inherit the implementation of other (non-abstract) methods. You can't do that with interfaces - an interface cannot provide any method implementations.
Sunday, June 01, 2008
Dev : Informix's Logical Log Files 2
I once wrote something on Informix's logical log file issue. After some research online and reading the manual, I can conclude that, for an Informix DBA, most importantly is to frequently monitor the database's logical log file.
As we do an "onstat -l", you might notice something like this:
8cd23475 U------ 1234 1:12345 1000 1000 100.00
8cd23476 U------ 1235 1:23423 1000 1000 100.00
8cd23477 U---C-L 1236 1:65434 1000 750 75.00
8cd23478 U-B---- 1237 1:15543 1000 1000 100.00
8cd23479 U-B---- 1238 1:12553 1000 1000 100.00
Some of the most important thing you might want to see is the "B", "C" and the last number column.
Remember this, the database will stop functioning when the next logical file is not backup. It does not concern whether the next is fill up or not, instead, backed up or not is more important. The last number column will stat the percentage of the logical file being used. So when it reaches 100%, it will move over to the subsequent file.
So, how to determine which logical log file is in use now? Noticed the "C"? It means the current logical log file is being written. For this case, it will continue to write the current, the next, and the next to the next's logical log file. When it reaches back to the 1st logical log file, the database will stop functioning. So, it is better to alway to backup the logical log file, "ontape -a", as often as possible. Maybe once a week?
"B" stands for backup-ed. So meaning that after a backup is being done, you will notice that all the logical log file will have a "B", except for the current logical logfile.
This is what I have understand after reading. I cannot assure that I am 100% correct, but then, hopefully it helps. Happy exploring!
As we do an "onstat -l", you might notice something like this:
8cd23475 U------ 1234 1:12345 1000 1000 100.00
8cd23476 U------ 1235 1:23423 1000 1000 100.00
8cd23477 U---C-L 1236 1:65434 1000 750 75.00
8cd23478 U-B---- 1237 1:15543 1000 1000 100.00
8cd23479 U-B---- 1238 1:12553 1000 1000 100.00
Some of the most important thing you might want to see is the "B", "C" and the last number column.
Remember this, the database will stop functioning when the next logical file is not backup. It does not concern whether the next is fill up or not, instead, backed up or not is more important. The last number column will stat the percentage of the logical file being used. So when it reaches 100%, it will move over to the subsequent file.
So, how to determine which logical log file is in use now? Noticed the "C"? It means the current logical log file is being written. For this case, it will continue to write the current, the next, and the next to the next's logical log file. When it reaches back to the 1st logical log file, the database will stop functioning. So, it is better to alway to backup the logical log file, "ontape -a", as often as possible. Maybe once a week?
"B" stands for backup-ed. So meaning that after a backup is being done, you will notice that all the logical log file will have a "B", except for the current logical logfile.
This is what I have understand after reading. I cannot assure that I am 100% correct, but then, hopefully it helps. Happy exploring!
Dev : Java Development Platform Environment
Java is considered as an platform independent development and application, or better known as WORA, which stand for Write Once, Run Anywhere. You can always develope your application on Windows, but run it on Linux, or maybe Solaris, or maybe AIX. As long as you have the correct version of JDK or JRE for that particular platform, any java application will run.
But yet, 1 basic rule for java development, never ever deploy to a platform that you never test your application on. In other words, if your production server is running on Linux, please test your application on Linux environment before moving into the production.
Why did I say so? Because, there are many different mechanism in different platform. For example, if you use your application to execute a Windows command, most probably you won't find that command in Linux. But the worse case is that you might not aware of that when writting the codes. Another fine example is the real path that you might use. You may use "\" in writting real path codes in Windows, but then, unix environment does not recognise this character as a path.
So, remember to test fully on the actual, or more to actual environment before planning moving into production.
But yet, 1 basic rule for java development, never ever deploy to a platform that you never test your application on. In other words, if your production server is running on Linux, please test your application on Linux environment before moving into the production.
Why did I say so? Because, there are many different mechanism in different platform. For example, if you use your application to execute a Windows command, most probably you won't find that command in Linux. But the worse case is that you might not aware of that when writting the codes. Another fine example is the real path that you might use. You may use "\" in writting real path codes in Windows, but then, unix environment does not recognise this character as a path.
So, remember to test fully on the actual, or more to actual environment before planning moving into production.
Tuesday, May 06, 2008
Dev : Informix's Logical Log Files are Full -- Backup is Needed
Due to certain condition, such as a big chunk of data is trying to roll back, Informix database server tend to use up all the logical spaces that are assigned to it.
If one day you found that your informix server is not functioning properly, why not check at the logical log file first? I've spend my whole day standing in the server room learning this lesson. This is how I manage to resolve it:
1. If logical file is full, You'll see this error in informix's log file : Logical Log Files are Full -- Backup is Needed. You will not be able to search certain tables and you may also encounter table lock often.
2. type onstat -l to list the list of logical file that you have. If it is due to this error, you will see most, if not all, logical space is 100%.
3. type onmode -l to clear logical log file.
4. If the logical space is fully utilised, onmode -l cannot be use. It will not succeed. You need to goto %informix%/etc/onconfig.std (%ONCONFIG file), change the LTAPEDEV value to /dev/null.
5. Run ontape -a to run backup. Follow instruction.
6. Then run onmode -l again to clear logical file one by one.
7. Change back LTAPEDEV to its original value (/dev/tapedev).
8. Restart DB.
*p/s: I've updated the steps as previously I have missed out step number 5.
If one day you found that your informix server is not functioning properly, why not check at the logical log file first? I've spend my whole day standing in the server room learning this lesson. This is how I manage to resolve it:
1. If logical file is full, You'll see this error in informix's log file : Logical Log Files are Full -- Backup is Needed. You will not be able to search certain tables and you may also encounter table lock often.
2. type onstat -l to list the list of logical file that you have. If it is due to this error, you will see most, if not all, logical space is 100%.
3. type onmode -l to clear logical log file.
4. If the logical space is fully utilised, onmode -l cannot be use. It will not succeed. You need to goto %informix%/etc/onconfig.std (%ONCONFIG file), change the LTAPEDEV value to /dev/null.
5. Run ontape -a to run backup. Follow instruction.
6. Then run onmode -l again to clear logical file one by one.
7. Change back LTAPEDEV to its original value (/dev/tapedev).
8. Restart DB.
*p/s: I've updated the steps as previously I have missed out step number 5.
Wednesday, March 26, 2008
Dev : CVS History
I know everyone of us used to have the problem of finding what file we have updated to CVS recently and our current tortoise CVS doesn't allow to view history by project (I think so), so normally we will manually find the file and check the history 1 by 1. gosh... that's tiring...
I've found a cool software that might help us to do the job and cut down the time we wasted on checking files, and yes, it is free. Please goto
http://www.download.com/CVS-Logger/3000-2383_4-10411357.html?tag=lst-1
or goto download.com to find a software called "CVSLogger", download and unzip the application into your pc.
Steps To Open A Project (or specific folder, or specific file) History
1. Upon running the application, goto View --> Options.
2. Change the CVS executable path to your tortoise CVS home. Eg: C:\Program Files\TortoiseCVS
3. Click OK to save the changes.
4. Click File --> Open.
5. Locate the Project/Folder/file that you want to view the history.
6. Click OK to load the history.
7. Wait... It might take a long time to load all the history.
And there you are. With this, you can even filter the history by user basis. Enjoy with the new toy. Thanks alot to Sergey Zozulya for the cool application!
I've found a cool software that might help us to do the job and cut down the time we wasted on checking files, and yes, it is free. Please goto
http://www.download.com/CVS-Logger/3000-2383_4-10411357.html?tag=lst-1
or goto download.com to find a software called "CVSLogger", download and unzip the application into your pc.
Steps To Open A Project (or specific folder, or specific file) History
1. Upon running the application, goto View --> Options.
2. Change the CVS executable path to your tortoise CVS home. Eg: C:\Program Files\TortoiseCVS
3. Click OK to save the changes.
4. Click File --> Open.
5. Locate the Project/Folder/file that you want to view the history.
6. Click OK to load the history.
7. Wait... It might take a long time to load all the history.
And there you are. With this, you can even filter the history by user basis. Enjoy with the new toy. Thanks alot to Sergey Zozulya for the cool application!
Tuesday, March 11, 2008
Dev : Skipping CVS Folder In WinMerge
WinMerge is quite a powerful tool to compare text document and folders, and I am currently using WinMerge 2.4 for quite some time. Comparing folders content couldn't be easier.
But when it comes to comparing development folders with CVS, it could mean just one thing, a hell lot of files. If you have 100 subfolders, then you will see 200 CVS folders, and 200x6=1200 CVS config files. Add on with your original files, you could end up with 2000-3000 files at least.
So what other alternatives do I have to reduce the file compared and viewed? Yes you do. Firstly, use the WinMerge to compare 2 simple folder. After doing that, clickView. Uncheck "Show Identical Files" and "Show Skipped Files". Other than this, I have no idea how to show this menu without comparing anything, it wont even show if just comparing a file.
You wouldn't want to view identical files if you are to use WinMerge in the first place right?
Unchecking the "Show Skipped Files" need you to actually do this second step. Else, it will not take effect on anything. The second step is to create a filter. Click Open and a small window will appear as below.
Click Select beside the filter dropdown, and another window will appear to let you create your own filter. Click New. It will prompt you to choose whether the new filter will be used personally or share. Anyone will do. It doesn't matter. Create a new filter file name called "CVS Filter", and inside the filter file, edit it to look something like this (most importantly is the bolded part) :
## This is a directory/file filter template for WinMerge
name: CVS Filter
desc: CVS Filter
## Select if filter is inclusive or exclusive
## Inclusive (loose) filter lets through all items not matching rules
## Exclusive filter lets through only items that match to rule
## include or exclude
def: include
## Filters for filenames begin with f:
## Filters for directories begin with d:
## (Inline comments begin with " ##" and extend to the end of the line)
d: \\CVS$ ## CVS
Save it and there you go. Your new CVS filter is ready to be used with the unchecked of "Show Skipped Files".
Now, you will only see those files you really wish to see.
Monday, March 10, 2008
Dev : Java Code Exception, Getting Error Details
In java coding, we used to have try-catch statement mainly for capturing unforeseen code errors such as SQL query error, parsing a non number to number and as such.
Normally within the catch, we will either throw it back to the method that calls it, or print it out using printStackTrace(). If we were to print it to a string or a log file, we will use toString(). But then, printing to a log file using toString() method might not be sufficient for a developer.
[12:34:56] java.lang.NullPointerException
What does this means? I know the application is hitting some variables which had not been assigned to any value, but where is it? I had a thousand lines of code, which is hitting the error? My current catch is as such:
catch (Exception e) {
log.error(e.toString());
throw e;
}
Well, to get a better description on the log file, I would recommend to use these code instead of just e.toString():
catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.close();
log.error(sw.toString());
throw e;
}
These code will actually write the more descriptive printStackTrace() to a buffer, and we print the buffer out instead of writing it somewhere else. With these code, I am able to get better description, including which line and what class as such:
[12:34:56] java.lang.NullPointerException
at a.class.package.anotherMethod(NewClass2.java:87)
at a.class.package.newMethod(NewClass.java:890)
at a.class.package.main(NewClass.java:60)
Exception in thread "main"
Isn't it better than a single line printout?
Normally within the catch, we will either throw it back to the method that calls it, or print it out using printStackTrace(). If we were to print it to a string or a log file, we will use toString(). But then, printing to a log file using toString() method might not be sufficient for a developer.
[12:34:56] java.lang.NullPointerException
What does this means? I know the application is hitting some variables which had not been assigned to any value, but where is it? I had a thousand lines of code, which is hitting the error? My current catch is as such:
catch (Exception e) {
log.error(e.toString());
throw e;
}
Well, to get a better description on the log file, I would recommend to use these code instead of just e.toString():
catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.close();
log.error(sw.toString());
throw e;
}
These code will actually write the more descriptive printStackTrace() to a buffer, and we print the buffer out instead of writing it somewhere else. With these code, I am able to get better description, including which line and what class as such:
[12:34:56] java.lang.NullPointerException
at a.class.package.anotherMethod(NewClass2.java:87)
at a.class.package.newMethod(NewClass.java:890)
at a.class.package.main(NewClass.java:60)
Exception in thread "main"
Isn't it better than a single line printout?
Saturday, March 01, 2008
Dev : Replace CVS Files, All Files
Windows file REPLACE command is something very useful that every person should know, esspecially for developers. Let me try elaborate using a scenario.
Using Tortoise CVS in windows to backup as well as managing source code versioning is a life saving attemped. It can help you to know who commited what and most of all, it is free.
But then, what if one day, your source code administrator sends all developers an email :
"Hi,
From today onwards, all CVS source code in SUN server will be moved to MOON server due to disk space issue. Please change your workstation's settings accordingly.
Thanks.
From,
Admin."
For the time being, I wouldn't know if there is any other ways to make life easier on this matter. All my source code are pointing towards SUN and now you say MOON? Yeah right, easy for you to say... But first of all, how?
By knowing the behaviour of Tortoise CVS, like every developer knows, there will be a hidden folder called "CVS" in each folder that is using CVS for versioning control in your workstation. But what you should really know is that is what's in it. For the time being, lets get straight to the point.
In each hidden CVS folder, there will be a file called Root. The content of Root might appear differently depending on what CVS authentication you use. As example, ":sspi:mydomain\cksgary@sun:/cvs". Notice that the word "sun" behind "@"? This is the keyword. Just replace the sun with moon. But yet, that is not enough. Because there are more than 2 thousand subfolders that contain this Root file. It is not possible for me to change one by one even if I sacrifice my whole day doing this.
And here comes the real life saver. Using windows REPLACE command really helped out. Just follow the steps below :
1. Ok, lets say your working folder is "D:\work". Make a copy of this Root file in "D:\". Please make sure that it is renamed exactly the same as in the working one. Change the content accordingly.
2. Go to "START --> RUN --> type CMD". This will open a command prompt console for you.
3. Type "REPLACE D:\Root D:\work /s". This will then start replacing all files with the name of Root in all folders and subfolders in "D:\work" with the "d:\Root" file.
3 steps, and you're done. This could be used in any other scenarios if there is a need to replace all files with the same name.
Using Tortoise CVS in windows to backup as well as managing source code versioning is a life saving attemped. It can help you to know who commited what and most of all, it is free.
But then, what if one day, your source code administrator sends all developers an email :
"Hi,
From today onwards, all CVS source code in SUN server will be moved to MOON server due to disk space issue. Please change your workstation's settings accordingly.
Thanks.
From,
Admin."
For the time being, I wouldn't know if there is any other ways to make life easier on this matter. All my source code are pointing towards SUN and now you say MOON? Yeah right, easy for you to say... But first of all, how?
By knowing the behaviour of Tortoise CVS, like every developer knows, there will be a hidden folder called "CVS" in each folder that is using CVS for versioning control in your workstation. But what you should really know is that is what's in it. For the time being, lets get straight to the point.
In each hidden CVS folder, there will be a file called Root. The content of Root might appear differently depending on what CVS authentication you use. As example, ":sspi:mydomain\cksgary@sun:/cvs". Notice that the word "sun" behind "@"? This is the keyword. Just replace the sun with moon. But yet, that is not enough. Because there are more than 2 thousand subfolders that contain this Root file. It is not possible for me to change one by one even if I sacrifice my whole day doing this.
And here comes the real life saver. Using windows REPLACE command really helped out. Just follow the steps below :
1. Ok, lets say your working folder is "D:\work". Make a copy of this Root file in "D:\". Please make sure that it is renamed exactly the same as in the working one. Change the content accordingly.
2. Go to "START --> RUN --> type CMD". This will open a command prompt console for you.
3. Type "REPLACE D:\Root D:\work /s". This will then start replacing all files with the name of Root in all folders and subfolders in "D:\work" with the "d:\Root" file.
3 steps, and you're done. This could be used in any other scenarios if there is a need to replace all files with the same name.
Wednesday, December 05, 2007
Dev : Telnet-ing
A simple tips to share to everyone. As we know, each program that dwells through the network will be communicating through a certain specific port. For example, MSSQL2000 is using port 1433, SMTP is using port 25 and ssh is using port 22.
If we fail to connect, lets say, the mail server of the company, we can actually do a quick check on the problem. Using windows telnet to connect to the network port would be a great start. It will just take a couple of steps to check on the SMTP port of the mail server. Although telnet is defaulted to connect to port 23, but with an additional parameter, we can also telnet to any desire port.
Steps (Make sure your firewall is off and network is up for clearer picture)
1. Open your Command Prompt (Start --> Run --> cmd).
2. Type telnet mailserver 25.
3. If you receive such message Connecting To mailserver...Could not open connection to the host, on port 25: Connect failed, this means most probably the mail server itself is down or maybe the mailserver daemon is not running. Daemon is a small program running in the background either waiting for command or run on its own on a specific port.
4. If you success, you will be brought to a new blank page (normally). This means the mailserver and port is running fine. You will need to check your mail browser instead. Press keyboard ctrl+] to disconnect the telnet.
5. Type quit to exit the windows telnet.
This is very useful, esspecially if you are trying to set up a program such as Apache webserver but you are not sure whether it is running fine or not. You can try connect Apache webserver on the local machine by using telnet localhost 80.
*Keep in mind that normal telnet is telnet ip_or_hostname_of_machine. Telnet checking should be telnet ip_or_hostname_of_machine port_used.
If we fail to connect, lets say, the mail server of the company, we can actually do a quick check on the problem. Using windows telnet to connect to the network port would be a great start. It will just take a couple of steps to check on the SMTP port of the mail server. Although telnet is defaulted to connect to port 23, but with an additional parameter, we can also telnet to any desire port.
Steps (Make sure your firewall is off and network is up for clearer picture)
1. Open your Command Prompt (Start --> Run --> cmd).
2. Type telnet mailserver 25.
3. If you receive such message Connecting To mailserver...Could not open connection to the host, on port 25: Connect failed, this means most probably the mail server itself is down or maybe the mailserver daemon is not running. Daemon is a small program running in the background either waiting for command or run on its own on a specific port.
4. If you success, you will be brought to a new blank page (normally). This means the mailserver and port is running fine. You will need to check your mail browser instead. Press keyboard ctrl+] to disconnect the telnet.
5. Type quit to exit the windows telnet.
This is very useful, esspecially if you are trying to set up a program such as Apache webserver but you are not sure whether it is running fine or not. You can try connect Apache webserver on the local machine by using telnet localhost 80.
*Keep in mind that normal telnet is telnet ip_or_hostname_of_machine. Telnet checking should be telnet ip_or_hostname_of_machine port_used.
Wednesday, November 28, 2007
Dev : Getting HTML Dropdown/Combobox Label, Not Value
Something quite interesting on combobox my colleague had just asked me. Using javascript, how do we get the label value, instead of the real value of a combobox. well, umm... har.... how har? :-) I am not an expert in HTML and javascript, so scratching my head is the only thing I can do.
But after some research on the Net, I've found some resources that helped to solve the problem. You don't need to hide the label value somewhere or in the html option tag, just create your dropdown/combobox as normal, using this three tiny line of code in your javascript, and you're done!
var comboList = document.myform.combolist;
var comboValue = comboList.value;
var comboLabel = comboList.options[comboList.options.selectedIndex].text;
But after some research on the Net, I've found some resources that helped to solve the problem. You don't need to hide the label value somewhere or in the html option tag, just create your dropdown/combobox as normal, using this three tiny line of code in your javascript, and you're done!
var comboList = document.myform.combolist;
var comboValue = comboList.value;
var comboLabel = comboList.options[comboList.options.selectedIndex].text;
Monday, October 01, 2007
Dev : Tracing Users
My Gosh! Where is the file I have just created? It was here a minute ago....
So someone had log in and done something to your file. Who is it? You have over 100 co-workers here. So how do we actually see who had done something wrong? By using the command "finger" and "w", we might be able to get something straight.
Generally, the mighty "w" will help you to trace who had login to this server and what are they doing currently. "finger" instead, will let you see the list of logged in users, what time they are already in and from where (IP address) these users come from.
These are some commands that might help you to trace the culprit. There should be some other way to get a better "result" and I am still trying to study and find the best way, but for the time being, just bear with me. :-)
So someone had log in and done something to your file. Who is it? You have over 100 co-workers here. So how do we actually see who had done something wrong? By using the command "finger" and "w", we might be able to get something straight.
Generally, the mighty "w" will help you to trace who had login to this server and what are they doing currently. "finger" instead, will let you see the list of logged in users, what time they are already in and from where (IP address) these users come from.
These are some commands that might help you to trace the culprit. There should be some other way to get a better "result" and I am still trying to study and find the best way, but for the time being, just bear with me. :-)
Subscribe to:
Posts (Atom)