After we know about select in database the next chapter is how to insert,update and delete data at oracle database using java programming language. First open your IDE for this case i will use Netbeans 6.8.Please attention in code bellow:
ConnectionDatabase.java
import java.sql.*;
public class ConnectionDatabase {
Connection conn=null;
public Connection getConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
String _user="dbContact";
String _pass="contact12345";
conn=DriverManager.getConnection(url,_user,_pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch ( SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main (String[] args) {
new ConnectionDatabase().getConnection();
}
}
InsertDatabase.java
import java.util.Scanner;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class InsertDatabase {
public ConnectionDatabase conn = new ConnectionDatabase();
public Connection conx = null;
public int _success = 0;
public InsertDatabase() {
String _id = "", _name = "", _address = "";
Scanner sc = new Scanner(System.in);
System.out.println("Insert Data");
System.out.println("------------------------");
System.out.print("ID\t: ");
_id = sc.next();
System.out.print("Name\t: ");
_name = sc.next();
System.out.print("Address\t: ");
_address = sc.next();
insertData(_id, _name, _address);
}
public void insertData(String _id, String _name, String _address) {
//Query syntax
try {
String sql = "Insert into Contact values(?,?,?)";
conx = conn.getConnection();
PreparedStatement stat = conx.prepareCall(sql);
stat.setString(1, _id);
stat.setString(2, _name);
stat.setString(3, _address);
_success = stat.executeUpdate();
if (_success == 1) {
System.out.println("Data successfully insert");
}
} catch (SQLException ex) {
Logger.getLogger(InsertDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
new InsertDatabase();
}
}
Note: Don't use space in insert data.
Result:
UpdateDatabase.java
import java.sql.*;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class UpdateDatabase {
public ConnectionDatabase conn = new ConnectionDatabase();
public Connection conx = null;
public int _success = 0;
public UpdateDatabase() {
String _id = "", _name = "", _address = "";
Scanner sc = new Scanner(System.in);
System.out.println("Update Data");
System.out.println("------------------------");
System.out.print("Update ID[Enter ID you want delete]\t: ");
_id = sc.next();
System.out.print("Name\t: ");
_name = sc.next();
System.out.print("Address\t: ");
_address = sc.next();
updateData(_id, _name, _address);
}
public void updateData(String _id, String _name, String _address) {
//Query syntax
try {
String sql = "Update Contact set Name=?,Address=? where ID=?";
conx = conn.getConnection();
PreparedStatement stat = conx.prepareCall(sql);
stat.setString(1, _name);
stat.setString(2, _address);
stat.setString(3, _id);
_success = stat.executeUpdate();
if (_success == 1) {
System.out.println("Data successfully update");
} else {
System.out.println("Data failed update");
}
} catch (SQLException ex) {
Logger.getLogger(UpdateDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
new UpdateDatabase();
}
}
Note: Don't use space in insert data.
Result:(Update name and adress in id 2(Before:Tommy Oxford. After Tana Captain))
Before Update
After Update
DeleteDatabase.java
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DeleteDatabase {
public ConnectionDatabase conn = new ConnectionDatabase();
public Connection conx = null;
public int _success = 0;
public DeleteDatabase() {
String _id = "";
Scanner sc = new Scanner(System.in);
System.out.println("Delete Data");
System.out.println("------------------------");
System.out.print("Delete ID: ");
_id = sc.next();
deleteData(_id);
}
public void deleteData(String _id) {
//Query syntax
try {
String sql = "Delete from Contact where ID=?";
conx = conn.getConnection();
PreparedStatement stat = conx.prepareCall(sql);
stat.setString(1, _id);
_success = stat.executeUpdate();
if (_success == 1) {
System.out.println("Data successfully delete");
} else {
System.out.println("Data failed deleted");
}
} catch (SQLException ex) {
Logger.getLogger(UpdateDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
new DeleteDatabase();
}
}
Result:
Okay that's is it and finally congratulation you have know how to insert,update,and delete data in java. I hope with this tutorial can help you...Thank You...^^
Sunday, January 30, 2011
How Insert, Update and Delete in Java (Oracle Database)
Select data from Oracle Database using Java
Okay in this chapter we will make connection between java and oracle database. First we will make user in Oracle.Copy code bellow in your oracle:
Query to create user in oracle database (Note log in with system)
create user dbContact identified by contact12345
grant connect,resource to dbContact
Query to make table in oracle (Note:Log in with dbContact)
create table Contact(
ID varchar2(100) primary key not null, Name varchar2(100), Address varchar2(100)
)
Query insert data to table Contact
insert into Contact values('1','Yohan Andreas','Babakan Jeruk I')
insert into Contact values('2','Hendry Apryanto','Kampung Hutan Tua')
insert into Contact values('3','Tana El San','Surya Sumantri')
Class in Java
ConnectionDatabase.java
import java.sql.*;
public class ConnectionDatabase {
Connection conn=null;
public Connection getConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
String _user="dbContact";
String _pass="contact12345";
conn=DriverManager.getConnection(url,_user,_pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch ( SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main (String[] args) {
new ConnectionDatabase().getConnection();
}
}
SelectDatabase.java
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SelectDatabase {
public ConnectionDatabase conn = new ConnectionDatabase();
public Connection conx = null;
public ResultSet set=null;
public SelectDatabase() {
String sql = "Select * from Contact";
conx = conn.getConnection();
try {
Statement stat = conx.createStatement();
set = stat.executeQuery(sql);
while (set.next()) {
System.out.println("ID Contact :" + set.getString("ID"));
System.out.println("Name Contact :" + set.getString("NAME"));
System.out.println("Address :" + set.getString("ADDRESS"));
System.out.print("\n");
}
} catch (SQLException ex) {
Logger.getLogger(SelectDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
new SelectDatabase();
}
}
Result:
Okay that's is it and congratulation you have made connection between java and oracle and you can display data. I hope this tutorial can help you..Thank you...^^
Saturday, January 29, 2011
Function in SQL Server 2005
This chapter we will discuss about function in sql server so let's check it out:
String Function
1. 'ASCII('[Word]')' -> Return ASCII Code.
Example:ASCII('A')->Result:65
2. 'Char([Word])' -> Return Character.
Example:Char(65)->Result:A
3. 'CharIndex('[Word]','[Sentence]')' ->Return position number word in sentence.
Example:CharIndex('E','HELLO') ->Result:2
4. 'Left([Word],[Number])' ->Taking the word as much a number at left.
Example:Left('HELLO',3)->Result:HEL
5. 'Ltrim([Sentence])' ->Clear space in left at sentence.
Example:Ltrim(' Hello')->Result:Hello
6. 'Right([Word],[Number])' ->Taking the word as much a number at right.
Example:Right('HELLO',3)->Result:LLO
7. 'Rtrim([Sentence])' ->Clear space in right at sentence.
Example:Rtrim('HELLO ')->Result:HELLO
8. 'Len([Sentence])' -> Calculate number of sentence.
Example:Len('HELLO')->Result:5
9. 'Lower([Sentence])' -> Change capital word to lowercase.
Example:Lower('HELLO')->Result:hello
10. 'Reverse(['Sentence'])'->Reverse the Sentence.
Example:Reverse('HELLO')->Result OLLEH
11. 'Upper([Sentence])'->Change lowercase to capital word.
Example:Upper('Hello')->Result:HELLO
12. 'Substring([Sentence],[Start Number],[Number of word])'-> Taking word from start number to number of word.
Example:Substring('Hello Word',2,2)->Result:ll
Date Function
1. 'Getdate()'->Return Complete date.
2. 'datepart(dd,getDate())'->Take a date and month.
3. 'datename(dw,'1980-06-11')'->Return day name at 11 Juny 1980.
4. 'dateadd(yy,2,getdate())'->Add 2 years from system today.
5. 'datediff(dd,'1980-06-11',getdate())'->Calculate the different between day.
Mathematics Function
1. 'abs(-25)'->Return absolute value.
2. 'sin(pi()/2)'->Calculate degree of sinus at 90 desgress.
3. 'exp(1)'->Calculate e power 1.
4. 'radians(180)'->Conversion 180 degress to radian.
5. 'power(2,4)'->Conversion 2 power 4.
6. 'rand(90)'->Rteurn random number under 90.
okay that's is it and finally congratulation you have learn about function in sql server. Thank you for see this tutorial I hope with this tutorial can help you...^^
Friday, January 28, 2011
Relation Operator in SQL Server
In this chapter we will learn about relation operator. Realtion Operator have a utility to make some condition in query syntax. At bellow is a little relation operator:
1. '=' -> Equal
2. '<>' -> Not Equal
3. '<' -> Less
4. '<=' -> Less than or equal to
5. '>' -> Bigger
6. '>=' -> Bigger than or equal to
7. 'Like' -> Usually use symbol '%'
8. 'IN' ->Search by parameter more than 1
9. 'Between' -> Search for 2 condition
10. 'Not Between' -> Not between 2 condition.
11. 'Null' -> Empty Value
12. 'Not Null' -> Not Empty Value
Example
Create database dbStudent
Create table dataStudent(
NRP varchar(100) primary key not null, Name varchar(100), Grade int
)
Insert into dataStudent value('0772186','Hendry Apryanto',40)
Insert into dataStudent value('0772097','Yohan Andreas',60)
Insert into dataStudent value('0772232','Tommy Gunawan',90)
Insert into dataStudent value('0772185','Junius',40)
Insert into dataStudent value('0772111','Tana El San',50)
1. Using Equal Symbol ('=')
Select * from dataStudent where NRP='0772186'
Result:
NRP = 0772186
Name = Hendry Apryanto
Grade = 40
2.Using Not Equal Symbol ('<>')
Select * from dataStudent where NRP <> '0772186'
Result :
NRP = 0772097
Name = Yohan Andreas
Grade = 60
NRP = 0772185
Name = Tommy Gunawan
Grade = 90
NRP = 0772185
Name = Junius
Grade = 40
NRP = 0772111
Name = Tana El San
Grade = 50
3. Using Less and Less Than or Equal to('<' and '<=')
Select * from dataStudent where Grade < 50
Result:
NRP = 0772186
Name = Hendry Apryanto
Grade = 40
NRP = 0772185
Name = Junius
Grade = 40
Select * from dataStudent where Grade <= 50
Result:
NRP = 0772186
Name = Hendry Apryanto
Grade = 40
NRP = 0772185
Name = Junius
Grade = 40
NRP = 0772111
Name = Tana El San
Grade = 50
4.Using Bigger and Bigger than or equal to ('>' and '>=')
Select * from dataStudent where Grade > 60
Result :
NRP = 0772185
Name = Tommy Gunawan
Grade = 90
Select * from dataStudent where Grade >= 60
Result :
NRP = 0772097
Name = Yohan Andreas
Grade = 60
NRP = 0772185
Name = Tommy Gunawan
Grade = 90
5. Using Like
Select * from dataStudent where Name LIKE '%h%' (Check at column name containt 'h' word)
Result:
NRP = 0772186
Name = Hendry Apryanto
Grade = 40
NRP = 0772097
Name = Yohan Andreas
Grade = 60
6. Using IN
Select * from dataStudent where Name IN ('Yohan Andreas','Hendry Apryanto')
Result:
NRP = 0772186
Name = Hendry Apryanto
Grade = 40
NRP = 0772097
Name = Yohan Andreas
Grade = 60
7. Using Between
Select * from dataStudent where Grade between 50 and 80
Result:
NRP = 0772097
Name = Yohan Andreas
Grade = 60
NRP = 0772111
Name = Tana El San
Grade = 50
8. Using Not Between
select * from dataStudent where Grade not between 40 and 70
Result:
NRP = 0772185
Name = Tommy Gunawan
Grade = 90
9. Using Null and Not Null
Select * from dataStudent where Name is null
Result:
(No data)
Select * from dataStudent where Name is not null
Result:
NRP = 0772186
Name = Hendry Apryanto
Grade = 40
NRP = 0772097
Name = Yohan Andreas
Grade = 60
NRP = 0772185
Name = Tommy Gunawan
Grade = 90
NRP = 0772185
Name = Junius
Grade = 40
NRP = 0772111
Name = Tana El San
Grade = 50
Okay that's is it and finally congratulation you know a little relation operator in sql server. Thank you for see this tutorial, I hope with this tutorial can help you..^^
Thursday, January 27, 2011
How to Change Table Sructure Using Sql Command
Okay in this chapter we will discuss how to change table structure using sql command. fisrt open your SQL Sever. In this case I will use sql server 2005, Choose root of database->Choose Tools menu and click at new query. after that query analyzer will display. Query Analyzer is place to write sql command.
For Example I will create some table:
Create table dataStudent(
NRP varchar(100), Name varchar(100)
)
Create table dataSubject() {
Number varchar(10) primary key not null, Name_Subject varchar(100), NRP varchar(100)
}
How to Add Column at Table(I will add column Address at dataStudent)
Format:Alter table [Table Name] add [Add Column] [Data Type]
Example: Alter table dataStudent add Address char(100)
How to change column data type at table (I will change data type column Address at dataStudent)
Format:Alter table [Table Name] alter column [Add Column] [Data Type]
Example:Alter table dataStudent alter column Adress varchar(100)
How to delete column at table (I will delete column Adress at dataStudent)
Format:Alter table [Table Name] drop column [Column Name]
Example:Alter table dataStudent drop column Address
How to add constraint primary key (I will add primary key to NRP column)
1. If you want make column as primary key you must add not null at column.
Example :Alter table dataStudent alter column NRP varchar(100) not null
2. Add Constraint to column
Format: Alter table [Table Name] add contraint [Name Primary Key] primary key [Column Name]
Example:Alter table dataStudent add contraint pk_Student primary key(NRP)
How to add contraint foreign key at column in Table(I will make foreign key between table dataSubject->dataStudent(Primary Key))
Format:Alter table[table candidate foreign key] add constraint [Contraint Name]([Column Name]) reference [table primary key](Column Name)
Example:Alter table dataSubject add contraint fk_Subject_ref_Student foreign key (NRP) reference dataStudent(NRP)
How to delete constraint (I will delete fk_subject_ref_Student)
Format:Alter table [Table Name] drop contraint [Constraint Name]
Example:Alter table dataSubject drop contraint fk_subject_ref_Student
How to drop table (I will drop table dataSubject)
Format:Drop table [Table Name]
Example:Drop table dataSubject
Okay that's is it. Congratulation you have learn a little sql command. I hope this tutorial can help you. Thank a lot..^^
Read More......
Wednesday, January 26, 2011
Introduction SQL Server
SQL Server is database management product. Released by Microsoft and name with Micorosft SQL Server Management Studio for this case I will use SQL Server 2005.
SQL Server have a utility to make table, view, trigger, store procedure, and many object the other.
This is step to make database:
1. Right click at part database and choose new database.
2. Fill at database menu for example dbStudent, at default it will make 2 file(dbStudent.mdf and dbStudent.log).
3. We can configuration like file type, initial type, autogrowth, path, or you can use a default setting.
4. Press ok and database will make by system.
The other way you can write a query syntax
"Create database [Name Database]"
For Example:
"Create database dbStudent"
This is step to make column in database:
1. At object explorer, choose tables folder and right click adn then choose new table.
2. Fill field and type of properties (for example varchar, date, double).
3. Choose save or you can press a shortcut CTRL+S and give a name of column.
The other way to create column
"Create table [Name of table]([Name Variables][Data type])"
For Example:
"Create table _studentData (No varchar(100) primary key not null,Name varchar(100))"
This is step to insert data at column:
1. Choose table you want insert data
2. After that right click and choose Open table
3. Fill data (it will save automatic if you change a row)
The other way to insert data
"Insert into [Name Table] values ([Data])"
For Example:
Insert into dbStudent values('1234','Hendry Yeah')
This is step to update data at column:
1. Choose table you want update data
2. After that right click and choose Open table
3. Fill data with new one (it will save automatic if you change a row)
The other way to update data
"Update [Name Table] set [Property]=[Data]"
For Example:
Update dbStudent set No='123', Nama='Hendry Apryanto' where No='1234'
This is step to delete data at column:
1. Choose table you want delete data
2. After that right click and choose Open table
3. Delete data (it will save automatic if you change a row)
The other way to DELETE data
"Delete from dbStudent where [Property]=[Data you want deleted]"
For Example:
Delete from dbStudent where No='123'
okay that's all friend. I hope this tutorial can help you and finnaly Congratulation you have make process data in database...^^
Tuesday, January 25, 2011
Make Pyramid in Console Application (Java)
In this chapter we will make a pyramid using console application in java. Okay first, open your IDE. I use netbeans 6.8 with jdk1.6.0_18. After that, make a new project and new class (Class Name : "pyramid").
Source Code
import java.util.Scanner;
public class Pyramid {
public static void main(String[] args) {
int _heightpiramid = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Tutorial make pyramid in Java");
System.out.println("-----------------------------");
System.out.print("Entry height of pyramid : ");
_heightpiramid = sc.nextInt();
System.out.println("Result : ");
for (int x = 0; x < _heightpiramid; x++) {
for (int z = (_heightpiramid - 1) - x; z > 0; z--) {
System.out.print(" ");
}
for (int y = 0; y <= x; y++) {
System.out.print("*");
}
for (int y = 1; y <= x; y++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
Note :
1. Enter a number of height pyramid
I hope this tutorial can help you..^^
How make class in Java
Java programming language have utility to make a object. By creating object we can easy to access data, error handling, and the tidy code. okay no talk anymore let's make a one example.First open your IDE->Make a new project, there is have 2 class so i will describe one an one.
Student.java
public class Student {
private String _number,_name,_adress,_telpno;
public Student() {
}
public Student(String _number, String _name, String _adress, String _telpno) {
this._number = _number;
this._name = _name;
this._adress = _adress;
this._telpno = _telpno;
}
public String getAdress() {
return _adress;
}
public void setAdress(String _adress) {
this._adress = _adress;
}
public String getName() {
return _name;
}
public void setName(String _name) {
this._name = _name;
}
public String getTelpno() {
return _telpno;
}
public void setTelpno(String _telpno) {
this._telpno = _telpno;
}
public String getNumber() {
return _number;
}
public void setNumber(String _number) {
this._number = _number;
}
}
AccessClass.java
public class AccessClass {
public AccessClass() {
//make a new object Student and assign with name _student
Student _student = new Student();
// Set data from class _student
_student.setNumber("1234");
_student.setName("Hendry Apryanto");
_student.setTelpno("09090090");
_student.setAdress("California Street");
//Access data from class _student
System.out.println("Number :" + _student.getNumber());
System.out.println("Name :" + _student.getName());
System.out.println("Number Telphone :" + _student.getTelpno());
System.out.println("Address :" + _student.getAdress());
}
public static void main(String[] args) {
new AccessClass();
}
}
In student class I am desribe all property (Number,Name,Address,Number telphone) and method(Get and set for each property). Class student have a utility like a temporary data storage and we can set one on one property using method get and set. okay in AccessClass class I made object student so all property is assign to _student.At line 8-11 is using to assign data. At line 14-17 is using to get data.
okay and finnaly congurtulation you have made class and can access it. Thank you for see this tutorial...^^
How to Make Menu Bar in Java using Swing Libary
Menu bar is an essential part of application,because menu bar is give general features. okay let's make menu bar, first open your IDE->make a new project->make a new class (for instance:Class Name:MenuBarExercise.java)
Copy the code bellow:
import javax.swing.*;
public class MenuBarExercise {
private JFrame _frame = new JFrame("Exercise Menu Bar");
private JMenuBar _menubar = new JMenuBar();
private JMenu File = new JMenu("File");
private JMenu Data_Master = new JMenu("Master Data");
private JMenu Transaction = new JMenu("Transaction");
private JMenu About = new JMenu("About");
private JMenuItem Exit = new JMenuItem("Exit");
private JMenuItem Account = new JMenuItem("Account");
private JMenuItem Transfer = new JMenuItem("Transfer");
private JMenuItem Save = new JMenuItem("Save Money");
private JMenuItem Take = new JMenuItem("Take Money");
public MenuBarExercise() {
//Set property of JFrame component
_frame.setVisible(true);
_frame.setTitle("Exercise User Interface");
_frame.setExtendedState(_frame.MAXIMIZED_BOTH);
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE);
//Add Menu Bar into JFrame
_frame.setJMenuBar(_menubar);
// Set Menu to Menu Bar
_menubar.add(File);
_menubar.add(Data_Master);
_menubar.add(Transaction);
_menubar.add(About);
// Set Menu Item to Menu (File Menu)
File.add(Exit);
Transaction.add(Transfer);
Transaction.add(Save);
Transaction.add(Take);
Data_Master.add(Account);
}
public static void main(String[] args) {
new MenuBarExercise();
}
}
if the code is executed correctly it will display like this:
Congratulation you have made MenuBar in your java application. I hope this tutorial can help...Thank you..^^
Sunday, January 23, 2011
How to add Action Listener in Java
Action Listener have a utility to listen every action performed on a particular component.
For Example (Purpose: Result=Operator1+Operator2):
Result of source code:
Source Code
import java.util.Scanner;
public class Pyramid {
public static void main(String[] args) {
int _heightpiramid = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Tutorial make pyramid in Java");
System.out.println("-----------------------------");
System.out.print("Entry height of pyramid : ");
_heightpiramid = sc.nextInt();
System.out.println("Result : ");
for (int x = 0; x < _heightpiramid; x++) {
for (int z = (_heightpiramid - 1) - x; z > 0; z--) {
System.out.print(" ");
}
for (int y = 0; y <= x; y++) {
System.out.print("*");
}
for (int y = 1; y <= x; y++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
Note :
1. Entry a Operator 1 and Operator 2 Field
I hope this tutorial can help you..^^
Thursday, January 20, 2011
How to make JInternalFrame in Java
In this chapter we will make user interface in java with JInternalFrame component. JInternalFrame is a part from library java (import javax.swing.*). All component in java is using JFrame component to display to user, so we will make JFrame first. This is the hierarchy to using JInternalFrame in java.
1. Make the class with name "ExerciseUI.java".
2. Please follow source code bellow:
import javax.swing.*;
public class ExerciseUI {
private JFrame _frame = new JFrame();
private JInternalFrame _internalframe=new JInternalFrame();
private JDesktopPane _pane=new JDesktopPane();
public ExerciseUI() {
//Set property of JFrame component
_frame.setVisible(true);
_frame.setTitle("Exercise User Interface");
_frame.setExtendedState(_frame.MAXIMIZED_BOTH);
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE);
//Set property of JIntenalFrame component
_internalframe.setTitle("I'm in Frame Bro!!! Hahahaha");
_internalframe.setSize(500,500);
_internalframe.setVisible(true);
//Add JInternalFrame component to JDesktopPane component
_pane.add(_internalframe);
//Add JDesktopPane component to JFrame component
_frame.add(_pane);
}
public static void main(String[] args) {
new ExerciseUI();
}
}
Note :
1. At line 3 is library user interface that provided by java .
2. At line 7 is make object JFrame with name "_frame".
3. At line 8 is make object JInternalFrame with name "_internalframe".
4. At line 9 is make object JDesktopPane with name "_pane".
5. At line 13-16 is set property of JFrame.
6. At line 19-21 is set property of JInternal Frame.
7. At line 24 is add JInternalFrame to JDesktopPane.
8. At line 27 is add JDesktopPane to JFrame.
9. At line 29-31 is use to running the class.
Congratulation you have successfully created JInternalFrame component in java. Thank for see this blog if there is have mistake please revision from you..^^
Component in Java
In this chapter we will discuss about component in java. At bellow is component in swing libarary:
1. JLabel
->Have a utility to display a message, display tittle of component, and show picture.
Example :
Declaration-> JLabel _label=new JLabel("Hello Word");
or
JLabel _label=new JLabel();
_label.setText("Hello Word");
2. JButton
->Have a utility to handle event after click.
Example :
Declaration -> JButton _button=new JButton("Click Me");
or
JButton _button=new JButton();
_button.setText("Click Me");
3. JFrame
->Have a utility to display a form.
Example :
Declaration-> JFrame _frame=new JFrame();
//Set property in Java Frame
_frame.setVisible(true); (Display frame)
_frame.setTitle("Exercise User Interface"); (Tittle of frame)
_frame.setExtendedState(_frame.MAXIMIZED_BOTH); (Maximize frame)
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE); (Close Event)
Add Component in Frame -> JFrame _frame=new JFrame();
//Set property in Java Frame
_frame.setVisible(true); (Display frame)
_frame.setTitle("Exercise User Interface"); (Tittle of frame)
_frame.setExtendedState(_frame.MAXIMIZED_BOTH); (Maximize frame)
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE); (Close Event)
//Component
JPanel _panel= new JPanel();
//Add Panel to Frame
_frame.add(_panel);
4. JPanel
->A place to collect all component so all component can display together in monitor.
Example :
Declaration -> JPanel _panel=new JPanel();
Add Component to Panel -> JPanel _panel=new JPanel();
//Component
JLabel _label=new JLabel("Hello Word");
//Add Label to Panel
_panel.add(_label);
5. JRadioButton
-> Have a utility to make group radio button.
Example :
Declaration -> JRadioButton _radio=new JRadioButton("Chili");
Add Group RadioButton -> ButtonGroup _group=new ButtonGroup();
//Component Radio Button
JRadioButton _radioCar=new JRadioButton("Car");
JRadioButton _radioMotor=new JRadioButton("MotorCycle");
JRadioButton _radioJet=new JRadioButton("Jet");
//Add RadioButton to Button Group
_group.add(_radioCar);
_group.add(_radioMotor);
_group.add(_radioJet);
6. JBorder
->Add border decoration at form.Border in swing:
1. Line Border
2. Empty Border
3. Bevel Border
4. Compound Border
5. Etched Border
6. Lowered Bevel Border
7. Matte Border
8. Raised Bevel Border
Example:
Declaration -> JPanel _panel=new JPanel();
Border take = BorderFactory.createEtchedBorder();
take = BorderFactory.createTitledBorder("Transaction - Save Money");
_frame.setBorder(take);
7. JTextArea
->Use to entry data in application.
Example:
Declaration -> JTextArea _txtArea=new JTextArea();
8. JScroll Bar
Example:
Declaration -> JTable _table=new JTable();
JScrollPane _pane;
_pane=new JScrollPane(_table,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
9. JCheckBox
Example :
Declaration -> JCheckBox _box=new JCheckBox("Test");
Okay that's is is and finnaly congratulation you have know about a little component in java. Thank you for see this tutorial i hope with this tutorial can help you...^^
Wednesday, January 19, 2011
Java Connection To Oracle Database
In this chapter we will connect between Java and Oracle. Open your IDE to run java extension in this case I will use Netbeans 6.8.
1. Create a new java project (Click File -> New Project-> Java Application -> Project Name (For Instance:ConnectionDatabase)->Finish).
2. Create class ConnectionDatabase.java (At Source Package->Right Click->New->Java Class).
3. This is the source code to connect between Java and oracle (Note:Please input ojdbc14.jar in library of project). The oracle database is "ORCL" with user name "dbPercakapan" and Password "percakapan12345".
import java.sql.*;
public class ConnectionDatabase {
Connection conn=null;
public Connection getConnection() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
String _user="dbPercakapan";
String _pass="percakapan12345";
conn=DriverManager.getConnection(url,_user,_pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch ( SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main (String[] args) {
new ConnectionDatabase().getConnection();
}
}
Note :
1. At Line 6 statement is use to call driver name of oracle.
2. At Line 7 -10 is use to open connection in oracle.
If in the console display "Connection Successfully" you have made it connect it. ^^
Introduction Java Programming Language
Structure Java Program
Java is object oriented programming language. In java have a different way to write programming than the others. Source program in java is consist of classes. In classes is consists of attributes and method. Attributes is use to initializes data type while method is use to initializes procedure or function that will execute letter.
In java program have some class so there have 1 class will be main classes while other classes is complement.
This is a structure class in java:
public class [Class Name] {
[Variabel Definition]
...
[Constructor]
...
[Methods]
...
Public static void main(String[] args) {
...
}
}
Variabel
Variabel is a place to store data temporarily. If want to use variabel you must declare data type and name of variabel. In declaration variabel there have a rule, starting with letter and not containt special character like space, &, #, .,and other.
Data Type
1. Boolean = Return true or false.
2. Byte = Return between 1 byte (8 bit).
3. Char = Character or letter.
4. Double = Ranges value between (-1.7 x 10308) to +1.7E308 (+1.7 x 10308).
5. Float = Range value between -3.4E38 (-3.4 x 1038) to +3.4E38 (+3.4 x 1038).
6. Int = Integer.
7. Long = Long Integer.
8. Short = Short Integer.
Operators
Operators is sepecial command in java to modification process or selection with certain criteria to produce a new information or a new condition.
1. Aritmethic Operators
->This operator is used to calculate and aritmethic process. Aritmethics operators is usually used by programmer to produce number output.
- + -> Plus
- - -> Minus
- * -> Times
- / -> Divide
- % -> Modulo
- + -> Plus 1
- - -> Minus 1
2. Logical Operators
- & ->AND
- || -> OR
- ! -> NOT
3. Relational Operator
- == -> Equal than
- != -> Not Equal
- > -> Bigger
- < -> Less
- >= - >Bigger than
- <= -> Less than
Okay that's is it. Thank you for see this tutorial I hope this tutorial can help you..^^