Saturday, December 29, 2007

SQL Sub Query

I was having some problem with a SQL query few hour ago, it required me to write a sub query to execute it correctly.

Hmm, not good, heavy process.

Wednesday, December 19, 2007

If & Else If


These two set of codes seem like having no different. It seem like "return" make "else if" useless.

Wednesday, November 21, 2007

AccessDataSource & SqlDataSource

I used AccessDataSource tag in ASP.NET to connect a Microsoft Access Database, accidentally found this weird problem. The code is like this:

This code having no problem on localhost IIS server, but when I move it to my web hosting, it return "Access Deny to Database" kind of message.

So, I was thinking what wrong with this code? Then I find Mr. Google and saw this:
"The AccessDataSource will not connect to an Access database that is password-protected; to retrieve data from a password-protected Access database, use the SqlDataSource control."

Ei, but how come localhost manage to run it? Not understand. But, I guess I just need to use SqlDataSource in stead, problem solved, question remain unknown.

Monday, November 19, 2007

Microsoft ASP.NET 2.0 Vs Java Apache Struts

Hehe, another Microsoft & Java comparison.

Overall, both of them having a quite complete framework which let developers easy to develop web application.

ASP.NET 2.0 & Apache Struts framework comparison:

1) .NET Master Page = Struts Tiles Definition (Something like layout)
2) .NET Theme & Skin, Struts don't have this feature. (Store all the images, css in one place, make it easy to change from one set to another set)
3) Struts URL remap from .jsp to .do, .NET don't have this feature. (The jsp file for http://www.abc.com/index.do can be store at //server-root-path/somename/main.jsp, outsider won't know where is the exact location of the jsp file)
4) Struts Business Logic & Presentation Layer Separate, .NET don't have this feature. (Business logic centralize at Struts Action, separate from presentation layer which is the jsp, jsp only use to display selected data, all the logic on select what data out program at Struts Action)
5) Both have Resources for localization.
6) Both have Pre-compilation, create a cache copy on the server, let user open a website faster.

Secondly is the software use for web development:

1) Microsoft ASP.NET 2.0 - Microsoft Visual Studio 2005 (NOT FREE) or Microsoft Visual Web Developer (FREE) + Microsoft .NET Framework 2.0

2) Java Apache Struts - Netbeans (FREE) or Eclipse (FREE) + Struts plug in

Thirdly is how easy to pick up these new framework:

1) Microsoft ASP.NET 2.0 - I find it quite easy to learn. There are a lot of online resources available to view or download. I like W3Schools the most, all the basic information can get from there, easy to understand also.

2) Java Apache Struts - I find it hard to learn. There are too many things to handle for create a single page, struts-config, tiles-definition, application-resources, Action, Form & jsp 6 things. I took quite some time to pick up this framework.

But the way, I still haven't fully discover all the .NET features, I might miss out some important features on .NET. Overall, I like .NET, it is easy to learn.

Thursday, November 15, 2007

Java Class Cache Problem

I found this cache problem during my development. Example of how this problem can be happen:

If these two java files compiled into class files previously, then we might need to be careful when changing the "planId" constants value. The problem happen when we change the "planId" value to some other value & only compile the Constants.java file. In this case, Main.class file still refer to previous "planId" value which is "999".

So, the best solution is to remove all the classes & compile all java files again which we called it as Clean Build.

Thursday, November 8, 2007

"div" Tag

I facing a lot of problems with "div" tag in IE browser, I just wondering is it IE not understand this tag or they don't want to understand this tag.

Just fix a small bug on IE browser which they don't understand "whitespace: pre" CSS under "div" tag, I use "pre" tag then the problem solve.

pngfix.js

Recently facing some problems on PNG transparent images in IE6 browser. The solution is include this javascript:

It seem like this javascript is quite common in used when I try make a Google search. This script change all the images object in a web page to span object and calling a Microsoft library to make PNG images transparent.

Only need to do this on IE5.5 & IE6.

Thursday, October 18, 2007

Programming Trick

Here is some trick to let the code run faster, I face this long time ago, finally I am able to write it down.

For CodeA & CodeB:

The different will be very big when the String Array gone larger. If let say the size of the String Array is 100, CodeA will create 100 Integer object to store it's size, the program will end up like this CodeC.

Obviously, every loop set the String Array size is unnecessary. So, it is alway better to keep CodeB practice.

Wednesday, October 17, 2007

"code" Support

Yo, I add in something that will be useful on my own posting since I am a programmer.

Here is the CSS I used to create this "code" tag:

I am still thinking how to implement this into RSS feed which is a XML, not support CSS. If you didn't understand what I mean, open this post in a browser, then you will see the different.

How to use Netbeans to generate Javadoc

I guess somebody already know this, but I think there are somebody who didn't know it as well, so, I just put it up here.

Next time when you having development in Netbeans, try to write comments using its Auto Comments feature.

So, after all the comments had been write, you just need to right click on the project and click on "Generate Javadoc", then this will come out.

Sunday, July 8, 2007

Microsoft Access SQL Problem

I am having problem with this SQL in MS Access:

This query seem like working fine in most SQL software but not in MS Access. Either I or MS Access suck.

Saturday, July 7, 2007

SQL Injection

I had been heard "SQL Injection" since last 2 years, but until now I still haven't completely implement it on my website.

Last time Francis Pang hack into my website by login as my username to post here. Owcs also got mention to me about this. Furthermore, my colleague recently keep on remind us to avoid SQL Injection coding style.

Here some nice SQL Injection Walkthrough, teach us how to become web hackers.

Here I found some common solution for "SQL Injection" -- SQL Injection Attacks: Are You Safe?. But I dun think I can implements the killChars() function here. (I already implements stripQuotes() function long time ago)

Other than SQL Injection, I also found this -- Calling MS Access Parameterized Queries from ASP. Something like Hibernate, manage all the queries in one place. I think I will implements this as well.

Tuesday, July 3, 2007

Char to Varchar

I am facing some problem in some SQL coding recently.

The problem is like this:
A database field having a data type of Char[3], when using java coding style to execute the SQL, it automatically convert the data to java.lang.Character, which I don't understand why a Char[3] (Example: "abc") can converted into java.lang.Character (Example: "a"). The last 2 characters had been eaten.

So, my solution will be changing the SQL code from [select testAbc from tableAbc] to [select cast(testAbc, varchar(3)) from tableAbc]. With the help of "Cast", it finally manage to convert the data to java.lang.String & output correctly.

Friday, June 29, 2007

Dynamically Creating PDFs in a Web Application

I found this tutorial pretty useful, creating a PDF using iText without storing it, but stream out to the client browser.

Here the tutorial: Dynamically Creating PDFs in a Web Application

Saturday, June 23, 2007

Struts Form & request.setAttribute()

If using request.setAttribute("xxxList", xxxList) method to set the List Object, call below code to get the List Object to display in a JSP: "request_attribute.xml"

If using a List xxxList variable in Struts xxxForm, call below code to get the List Object to display in a JSP: "struts_form.xml"

Wednesday, April 25, 2007

XML and HTML character entity references

List of XML and HTML character entity references, I found this very useful references, so just put it up in case I forget the link again.

Anybody know how to put ™ & © in XML? Here my example:

Monday, March 12, 2007

Unclosed connection

Recently I facing this words too much, which is "Unclosed connection".

Normally when open a database connection with either Statement, Prepare Statement, Call Procedure, Result Set or Record Set , it need to be close at end of the page.

I faced this on my company project & my current website. After close the database connection at end of the page, the server didn't hold up a lot of objects, didn't use up all the memory & didn't make the server die.

* If there is some redirect code within the page, remember to close database connection before redirect as well.

Wednesday, February 28, 2007

J2ME HttpConnection POST

I was trying to make a J2ME HttpConnection POST for the last few week, finally I found out how to do that.

Hope this example code does help other ppl.