Pages

Subscribe:

Ads 468x60px

5/25/11

Connect Java and Database (2) Create Database

After XAMPP running, then make a new database using phpmyadmin. You may open your browser and click this URL : http://localhost/phpmyadmin/ there'll be a view like this and you may create a database name "databasename" like I do.
 Then it would be:

Then make a new java project in NetBean, which filled with syntax that could edit the database's proses such as update, delete, insert, etc.
 Then include the driver for java and mysql in Libraries :
then choose MySQL JDBC Driver, but before that you must download it in http://dev.mysql.com/downloads/connector/j/. And you must copy mysql-connector-java-5.1.12-bin.jar to c:/programfile/java/jdk/jre/lib/ext if you are use a windows OS, so do with directories org and com to src folders of your NetBean projects example : D:\NetBeansProjects\javamysql\src.

Next is make a new .java files for connecting the database with java and the main program for execute it. First make a java file named Connecting that have a syntax like this :
And make a main.java for syntax like this :
Then when you execute Main.java, it must be like this :
 Next we'll make a program for database operation..^_^

5/15/11

Connect Java and Database (1) Install XAMPP

Today i'll make an connection between java and database, for the database itself, i'll use XAMPP that can be downloaded in http://www.apachefriends.org/en/xampp-windows.html. And for java and databse connector, i'll use http://dev.mysql.com/downloads/connector/j/.
First of all, install XAMPP on your computer, like this and make an table of database.
 When it's done, double klik XAMPP Control Panel on your dekstop shortcut or from START >> All Program >> Xampp for Windows >> XAMPP Control Panel.
And make sure that the Apache, and MySql is running.
Then let's make a database with MySql, firstly you may access localhost on your webrowser and choose phpmyadmin or http://localhost/phpmyadmin/.




It would shown like this :
There's a warning there that shown there are error in MySQL privileged account. To repair it, click on the “Privilaeges” bar on the top then in “User : root, Host : localhost” choose “edit Privileges” then type your new password on Change Password.
 if there's an error then :
a. Open directory when you install it (C:/Program Files/XAMPP) choose folder : phpMyAdmin then choose config.inc.php (open with notepad).
b. Find line : $cfg['Servers'][$i]['password'] = ' '; type your password then it would be $cfg['Servers'][$i]['password'] = 'your_password';
c. Save your editing
d. Restart your XAMPP (stop then start again..)
e. The error has been fixed

Reference :
http://ayoespot.blogspot.com/2010/01/cara-memberi-password-pada-xampp-for.html

5/5/11

How to make a visualisation of caverage

In my project, i have create a limitation such as :
1. Size of coverage area is 100 x 100 m
2. Total of sensor that used is 4 sensors
3. Every sensor's radius are randomly pick base on the table bellow :
The table itself is taken from Sami J. Habib's paper Modeling and simulating coverage in sensor networks. For visualize the area in Java, firstly we create a new class in NetBean like this :
*Because i have create firstmutation.java for this project.
a new class is created and import these for create a GUI :
import java.awt.*;
And because we make a class that have a characteristic of class Frame, since we need to make a frame for GUI. So, it should be like this :
i set class secondmutation extends Frame as a main class, that's why on class main, i make an object from secondmutation extends Frame class. Which lead the running program to method secondmutation, where's the CanvasKu is called. In method secondmutation, we set the size of frame with this syntax:
setSize(160,160);
Then, make an object of class CanvasKu, and we add that object on the frame. The object will call the progress from class Canvasku where's i put the program of inisialitation and coverage's calculation there. Since CanvasKu is a class that create a canvas on top of frame, so it should have characteristic like Canvas class. That's why the program is should be like this :
And the output of this program would be like this :
because it's random so the second run and another would be different, such as: