Saturday, September 20, 2008

Simple and free Database for Development - Choose Oracle XE or MySQL

Any Web Application, may be that of a moderate size or a huge one needs a DataBase to maintain data.A Database makes a Developer/User/Maintenance person job easier as the data is always seperate from your application.Its a a simple file that is storing your data.You can always retreive your data with the code that you write and is completely up to us on how we get our data .. and most of all its fast and is secure.
Comming to the selection of a database that you need for your development i suggest the developers to take up Oracle XE database which is free version of oracle DB or MySql which is again a free open source database.
Here are some links which might help you.

http://www.oracle.com/technology/products/database/xe/index.html
http://oss.oracle.com/oracle-database-xe.html

http://www.mysql.com/
http://en.wikipedia.org/wiki/MySQL

Jar Explorer

http://jarbrowser.sourceforge.net/
http://sourceforge.net/projects/jarbrowser/



I recently had an encounter with the JarBrower s/w on the sourceforge.net and that was which could help me a lot at time.
A give a simple explanation a jar browser is something very simmilliar to that of a winzip.With winzip you can browser through all the files in the zip files.Simmillarly with jar broswer you can browse through all the class files in a jar file.No just that , jar browser had a an in build jad the famous open source java decompiler with it.You can not only browse through the jar file for the class files but also see the source code with in that.
However is felt a gap in this s/w ,we can see the src in a class file, but the we are not able to see the other simple text files like xml, properties file in the browser.Also we cannot view the images.I feel adding this feature would make the Jar Explorer more powerful and more and more useful.



Sunday, September 14, 2008

JAR - Command Reference

Common JAR file operations

To create a JAR file
jar cf jar-file input-file(s)

To view the contents of a JAR file
jar tf jar-file

To extract the contents of a JAR file
jar xf jar-file

To extract specific files from a JAR file
jar xf jar-file archived-file(s)

To run an application packaged as a JAR file
(requires the Main-class manifest header)
java -jar app.jar

To invoke an applet packaged in a JAR file to be displayed in your web page,put the following Tags.


<applet height="height" archive="JarFileName.jar" width="width" code="AppletClassName.class">
<param name="_cx" value="26">
<param name="_cy" value="26">
</applet>



Ref:http://java.sun.com/docs/books/tutorial/deployment/jar/

Tweaking MS Windows Command Prompt

Change the Font in the Command Prompt
http://smallvoid.com/article/winnt-cmd-add-font.html
http://phatness.com/node/1643

Add the "Open Command Prompt Here" Option in Windows Exploper
http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htm

Saturday, September 13, 2008

Introducing BNotepad 1.0.1.0

Writing an Application software on my own was a dream for me since the day one I started working with the software.Here I present you my first step towards it..
The BNotepad 1.0.1.0.



BNotepad is very simmilliar to the Notepad application that you find on the Microsoft windows.The difference being BNotepad is written by me... :).
BNotepad is written completely in java using JFC/Swing.The basic source code is taken from http://www.Planet-Source-Code.com/, Thanks to the developer for providing the skeleton code.
The difference that you find in the BNotepad is an additional Developer menu with menu items like
Convert JDBC to TNS
Convert TNS to JDBC
Wrap Sql View Definition and so on...
These are very specific functions which do some special tasks.
For example the "Convert JDBC to TNS" is a function which converts a given TNS String to a JDBC String.This is one of the very frequently made action for developers working on java and sql and BNotepad is Intended to make their life Simple.

I will be providing all the source code of the BNotepad online so the developers intresed in extending the tool or intrested to write their own functions can be ready to do that.
Any Suggestions/Comments/Bugs can be posted as the comments to this blog post.

You can use the BNotepad in two ways
1.Install the BNotepad as another other software using this link
or
2.Download the Jar file and run it directly.
You can choose to go whatever way you feel easy.

Have a happy coding.... :)

Convert TNS to JDBC String or TNS String to JDBC

For the developers who costantly work with the sql editor and then the java code (jsp or servlets), changing the connections string from tns to JDBC or JDBC to tns is a very common exercise .
Here im presenting some code to do this conversion.
Hope this will be help for some of u...

Convert JDBC to TNS

public void convertJDBC2TNS(){
System.out.println("In My button action listener");

//str is something like
//jdbc:oracle:thin:@ADDRESS:PORT:DBNAME
//we want the output to be something like
//XE=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)))


String str = n.getTextArea().getText();
String str2= new String();
System.out.println("My text is : \n"+str);

for(int i=0;i(lessthan)str.length();i++){
char c = str.charAt(i);
if(c==' '||c=='\t'||c=='\n'){
// do nothing
}
else{
char cl = java.lang.Character.toLowerCase(c);
char[] charArray ={cl};
str2 = str2.concat( new String(charArray));
}
}

System.out.println("String = "+str2+"\nlength = "+str2.length());
//XE=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)))

int hostIndex = str2.indexOf(":@");
int portIndex = str2.indexOf(":", hostIndex+1);
int sidIndex = str2.indexOf(":", portIndex+1);
System.out.println("hostIndex = "+ hostIndex+"\n portIndex = "+ portIndex+"\n sidIndex = "+ sidIndex );

int closingIndex;
closingIndex = str2.indexOf(":", hostIndex+1);
String host = str2.substring(hostIndex+2, closingIndex);
System.out.println("host = "+host);

closingIndex = str2.indexOf(":", portIndex+1);
String port = str2.substring(portIndex+1, closingIndex);
System.out.println("port = "+port);

//closingIndex = str2.indexOf(")", sidIndex);
String sid = str2.substring(sidIndex+1);
System.out.println("sid = "+sid);

//jdbc:oracle:thin:@ADDRESS:PORT:DBNAME
String tnsString = sid.toUpperCase()+"=(DESCRIPTION="+"\n\t"+
"(ADDRESS=(PROTOCOL=tcp)(HOST="+host+")(PORT="+port+"))"+"\n\t"+
"(CONNECT_DATA=(SID="+sid.toUpperCase()+"))"+"\n\t"+
")";
System.out.println("My text after conversion is : \n"+tnsString);
n.getTextArea().setText(tnsString);
}



Convert TNS to JDBC


public void convertTNS2JDBC(){
System.out.println("In My button action listener");

//your str is something like
//XE=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)))
//and you want to convert it to
//jdbc:oracle:thin:@ADDRESS:PORT:DBNAME

String str = n.getTextArea().getText();
String str2= new String();
System.out.println("My text is : \n"+str);

for(int i=0;i(lessthan)str.length();i++){
char c = str.charAt(i);
if(c==' '||c=='\t'||c=='\n'){
// do nothing
}
else{
char cl = java.lang.Character.toLowerCase(c);
char[] charArray ={cl};
str2 = str2.concat( new String(charArray));
}
}

System.out.println("String = "+str2+"\nlength = "+str2.length());
//mz5ms202=(description=(address=(protocol=tcp)(host=ap6005rems)(port=1575))(connect_data=(sid=mz5ms202))

int hostIndex = str2.indexOf("host");
int portIndex = str2.indexOf("port");
int sidIndex = str2.indexOf("sid");
System.out.println("hostIndex = "+ hostIndex+"\n portIndex = "+ portIndex+"\n sidIndex = "+ sidIndex );

int closingBraceIndex;
closingBraceIndex = str2.indexOf(")", hostIndex);
String host = str2.substring(hostIndex+5, closingBraceIndex);
System.out.println("host = "+host);

closingBraceIndex = str2.indexOf(")", portIndex);
String port = str2.substring(portIndex+5, closingBraceIndex);
System.out.println("port = "+port);

closingBraceIndex = str2.indexOf(")", sidIndex);
String sid = str2.substring(sidIndex+4, closingBraceIndex);
System.out.println("sid = "+sid);

//jdbc:oracle:thin:@ADDRESS:PORT:DBNAME
String jdbcString = "jdbc:oracle:thin:@"+host+":"+port+":"+sid+"";
System.out.println("My text after conversion is : \n"+jdbcString);
n.getTextArea().setText(jdbcString);
}

Syntax Highlighting the Source Code in Html/Blogs

Your text here...

<pre name="code" class="sql">
put your code here
</pre>

rest of ur text goes here...

Best Posts
http://en.blog.wordpress.com/2007/09/03/posting-source-code/
http://faq.wordpress.com/2007/09/03/how-do-i-post-source-code/


More...
http://blog.felho.hu/posting-source-code-in-wordpress-escaping-and-syntax-highlighting-the-inserted-code.html

Monday, September 1, 2008

My Hello world JSP... :)

Here is a short tutorial of how to create a simple hello world servlet and deploy it in a ApacheTomcat Server.
This is intended for the people who are very new to the JSP and servlets.
Ppl who are experts in the JSP and Servlets find this post very childish.... :D.

On an Overall view we will be doing the following simple steps.
Create a Severlet and its Deployment descripter.
Deploy it in a web server.
Run the page to test the servlet.

Step 1: Create a Project directory some where on your Hard drive.
Example: Create the main project directory HelloWorldApp and three subdirectories with name classes,etc and src respectively.



Step 2: Create a file with name HelloWorldServlet.java, You can copy paste the following code.Your are a java developer... so you can add in some more code here as well... :)




import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class HelloWorldServlet extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException{

PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html>"+
"<body>"+
"<h1 align=left>Hello World !!!</h1>"+
"<br>"+"Now the date and time is : "+today+"</body>"+"</html>");
}


}


Step 3: Create a deployment descriptor file i.e web.xml in the etc folder of your project.
Copy paste the following code.






HelloWorld Servlet
HelloWorldServlet


HelloWorld Servlet
/SayHello




Step 4:Compile your servlet classe and generate the class file under the classes folder of your project


F:\DevCore\HelloWorldApp>javac -classpath C:\ApacheTomcat6018\lib\servlet-api.jar -d classes src\HelloWorldServlet.java






Step 5: Create a folder HelloWorldApp under the Tomcat webapps folder.
Create a subfolder WEB-INF under the HelloWorldApp folder
Create a subfolder classes under the WEB-INF folder

Step 6: Copy the web.xml folder from your project directory ot the HelloWorldApp/WEB-INF folder under the Tomcat.
Copy the HelloWorldServlet.class file to the HelloWorldApp/WEB-INF/classes folder under the Tomcat.






Step 7: Start/Restart Apache Tomcat

Step 8: Enter the url "http://localhost/HelloWorldApp/SayHello" into your favourite Web browser...



Hurrah!!!.., here is your JSP Page running...

Ref : Chapter-1, Head First JSP and Servlets