Tuesday, June 23, 2009

Java oracle connection

In this article I am going to describe how to set up connection with oracle database from a java application.

Requirement:
To develop an application using Java and Oracle pc should have the configuration to support
java,Oracle Database, Apache-Tomcat Web Server , sufficient Space to store script.

Installation:
For developing java and Oracle based application, i proceeded in the following way:

1. installed "jdk-1_5_0_08-windows-i586-p" in C: / Program Files

2.installed oracle 9i.

3. Installed "jakarta-tomcat-5.5.7”, just unzipped it in D: \java2 folder like “D:\java-2\jakarta-
tomcat-5.5.7”

Java configuration:

I set up the following environment variables as user variable

1. “CATALINA_HOME “---- “D:\java-2\jakarta-tomcat-5.5.7”

2. “JAVA_HOME “----- “C:\Program Files\Java\jdk1.5.0_08”

3. “PATH “---- “C:\Program Files\Java\jdk1.5.0_08 \bin”

4. “CLASSPATH “---- “D:\java-2\jakarta-tomcat-5.5.7\common\lib\servlet-api.jar”

DSN configuration:

1. To get connection with oracle first I had to create a user that has a name “aditi” password “aditi” in oracle 9i.

The command is

create user aditi identified by aditi;
grant connect,resource to aditi;

2. Went to the System DSN and and click add button in the right side.

3. Selected “
Oracle in orahome90

4. Set “
myora” as Data Source Name and “dns for oracle” in Description.

5.Pressed test connection at the right side of this page and set “
aditi” in the service name and “aditi” in the password. Press ok.

6.It will give a confirmation massage like “connection successful”.

Now the DSN setting is finished.

Starting running my project:

Before I started the project at first I needed to run Oracle database server then “Apache-Tomcat" To start apache-tomcat I went to “D:\java-2\jakarta-tomcat-5.5.7\bin” then started the “startup.bat” file. After running the servers, went to “C:\apache-tomcat-5.5.15\webapps\” this folder, and created a new folder give a name to this folder like “OurEx” copied my project files in this folder.

Now I started my project

To start I opened my browser and in address bar write this

http://localhost:8081/OurEx/main and pressed enter after a few second it shows a login page.

The code for the login page is resides in main.java file. so when i ran the main.java from localhost, it shows the login page to me.

if I type my user name and password, it checks the username and password against the username and password stored in the oracle database, if matched it allows me to enter into the appliaction, other wise shows me a message that "wrong username or password"

For the port number 8080, a user may face problem, so he can change the port from 8080 to 8081.

This thing can be done as follows:

Go to this folder “D:\java-2\jakarta-tomcat-5.5.7\conf” then open “server.xml” file there find this

[ Connector port="8080" maxHttpHeaderSize="8192" ………..]

Change it to this

[Connector port="8081" maxHttpHeaderSize="8192" ………..]

Save and close the file then restart web server .

the port number that is used either in 8081 or 8080 or something other than this, should also be used in the code where ever port number is used. Unless application will not work correctly.

After this I hope there isn’t any problem that may be faced.



Monday, June 22, 2009

how to run a GTK based GUI program in linux

Running a GUI program in linux is much easier than that in windows.
here all the requirements for running a GTK program is installed with the operating system.
For example I ran GTK program in Fedora 10.
first I have checked whether my Fedora 10 system supports gcc compiler.
i wrote a simple c program and compile that program by writing the following command in terminal:
gcc test.c
it produced a output file name a.out.
then just typed ./a.out and this ran the c program.
after that i have checked whether my system has GTK installed.
to check that i issued a command in the terminal

rpm -q GTK2
this gives me the result.
gtk2-2.14.4-3.fc10.i386

I tested all other dependencies in the same way.
And finally when i found that my GTK and all other related packages are installed then i issued a command to run a GTK based program.

gcc te.c -o out1 `pkg-config --cflags --libs gtk+-2.0`

this gave a output file name out1
when i ran the out1 using ./out1 in the terminal i found my GTK program is running perfectly.






Saturday, June 20, 2009

How to build a button with Bengali level using GTK+ library

In this post i m going to discuss how can we create a button level with Bengali text using GTK library .
here i m showing a program which i ran using MinGW tools.

To do this thing first write a C program using GTK library.
here is a sample C code for creating a button.

#include <stdio.h>
#include
<gtk/gtk.h>

#define COLROW 5

gint Delete(GtkWidget* widget, gpointer* data)
{
g_print("Screw you guys, I'm going home!\n");
gtk_main_quit(); /* stop gtk_main */
return FALSE; /* Kill the window */
}

gint ButtonPressed(GtkWidget* widget, gpointer data)
{
g_print("You pressed the button.\n");
return FALSE;
}

int main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* button;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "test window");

button = gtk_button_new_with_label("hello");

gtk_container_add(GTK_CONTAINER(window), button);

gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(Delete), NULL);

gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(ButtonPressed), NULL);

gtk_widget_show(button);

gtk_widget_show(window); /* do this last */
gtk_main();

return 0;
}


the setting up level of a button is done in the line

button = gtk_button_new_with_label("hello");

if you want to write something in Bangla in stead of "hello" it will just show ????.
this is because this .c file is in ANSI format, cannot write any unicode text.
to edit some bangla text in this code you have to open this .c file either in Scite or Notepad++,.

and save the file in UTF-8 without Bom encoding. You can set this encoding from preference inside notepad++. after that you can write bangla text in any where in the file.
now replace the "hello" word with some Bangla word
.
Save the file.

so you have to configure your MinGW installation folder to tell GTK which bangla font you want to view in your application.
In order to do this, you need to open \etc\gtk-2.0\gtkrc file inside(create a gtkrc file if you dont have), where represents your gtk's installation directory, and place something similar to this

style "bangla"
{
font_name="Sans 9"
}
widget_class "*" style "bangla"

Replace "Sans 9" with our bangla font.

Thats it.
Now you run compile and run our progarm, you can see the Bangla word you set before in your button level.

Thursday, June 18, 2009

Crearting a simple window in C using GTK+ library in windows system

I have been trying to run a C program that uses GTK library.

At first I tried to use visual stdio 2005.
But I didnt succeed.

Then tried with MInGW and succeeded to run a GTK based GUI program.

I got help from the following two sites :
[0]http://www.daniweb.com/forums/thread86245.html#
[1]http://modulatum.wordpress.com/2008/06/02/get-started-with-gtk-using-mingw/
[2]http://www.gtk.org/download-windows.html

At first I followed all the procedure written in [0]

But this didnt running C GUI program .

So i Got help from the second website[1].

i followed from step 3

that means I got the GTK+bundle from [2] and extract it into my MinGW install directory.

This will replace the files that i have extracted there previously.

And followed the rest of the step mentioned in [1]

All these procedures I did to run a GTK based simple application in my windows system.

Now you can add more functionality and add more widgets by modify the hello.c code.