Thursday, January 28, 2010

Tutorial JDBC MySql (1)

In the programming, it does not complete if it does not discuss
database problems, which would make the program more
dynamic. This time, I will cite a brief skript
about how to create a database connection (JDBC) in the
java programming. DBMS used in this example is
MySql database. In my opinion, this is a MySQL connection
most easily done because they do not require configuration
complicated.

MySql default port is 3306.
Each DBMS has a port that each is different.
In PostgreSQL, the default port is 5432,
the SQLServer2000, the default port is 1433.
And this is the code :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

public class MemberDAOImpl implements MemberDAO {
private Connection connection;

public MemberDAOImpl() {
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306/bank";
connection = DriverManager.getConnection(url, "root",

"");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}


In order to make the connection can be called many times in other classes, add this script


public Connection getConnection(){
return connection;
}



For SQL scripts example, suppose a table is a 'member'.
This script can be made if the class for the entity member is made
first. If you need a file, you can contact me, I will send via email. And it so much easier to detect errors if we use the NetBeans application.

public List getAllMember() {
List listMember = new ArrayList
();
Connection conn;
Statement sttmt;
try {
conn = getConnection();
sttmt = conn.createStatement();
String query = "select * from member";
ResultSet rsMember = sttmt.executeQuery(query);
while(rsMember.next()){
Member member = new Member();
member.setRegNumber(rsMember.getString(1));
member.setId(rsMember.getString(2));
member.setName(rsMember.getString(3));
member.setGender(rsMember.getInt(4));
member.setClas(rsMember.getString(5));
member.setBirthPlaceDate(rsMember.getString(6));
member.setAddress(rsMember.getString(7));
member.setPhoneNumber(rsMember.getString(8));
listMember.add(member);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
return listMember;
}


That's the script to connect to MySql, for other DBMS I will discuss in the next examples. Good luck & Happy coding ^ _ ^!

By: Mr.Stanza

Wednesday, January 27, 2010

Qwerty Algorithm Tutorial

Java programming science is very broad and can be implemented in various fields. Among them are cryptographic. Cryptography itself is one branch of computer science in the world, which is associated with encoding or disguise the original text (plain text) into text that is disguised so as not to be understood by readers (chiper text).

Here is one example of the science of cryptographic algorithms called Qwerty (originaled by: Dwindy Stanza & Paiman). As the name implies, QWERTY, this algorithm adapted to the standard keyboard board. The principle works something like this:

A : index 0 = Q : index 0
B : index 1 = W : index 1
C : index 2 = E : index 2
D : index 3 = R : index 3
...
Z : index 25 = M : index 25

That's for the first letter, while for the second letter there is a shift in the index, so that A is no longer the Q, but the W. And Q was changed to the last index that W to M shifted one index. And so on.

A : index 0 = W : index 0
B : index 1 = E : index 1
C : index 2 = R : index 2
D : index 3 = T : index 3
...
Z : index 25 = Q : index 25

Prior to implementation of the program code, first create the components needed, ie
1. JPanel txtPlain
2. JPanel txtChiper
3. JButton btnEncrypt
4. JButton btnDecrypt

Encrypt used to translate the text into chiper Plain text, while Decrypt chiper translate text into plain text.

For implementation in java, something like this for action btnEncrypt:

private void btnEncryptActionPerformed(java.awt.event.ActionEvent evt) {
char [] kode = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M' };
char [] abc = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

int ketemu=0;
char tampung = 0;
String plaintext = txtPlain.getText();
char[] ciphertext = new char[plaintext.length()];

if (!plaintext.equals(""))
txtPlain.setText(plaintext);

for(int w = 0; w
tampung = plaintext.toUpperCase().charAt(w) ;
for(int x = 0 ; x<=25 ; x++){
if(tampung == abc[x] ){
ketemu = x;
}
// else{ ketemu = -1; }
ciphertext[w] = kode[ketemu];
}

char bantu = 0;

bantu = kode[0];
// Pergeseran Index
for(int i = 0 ; i<=24 ; i++ ) {
kode[i] = kode[i+1];
}
kode[25] = bantu;
}
String c;
for(int w = 0; w txtCipher.setText(String.valueOf(ciphertext));
}

}


As for the implementation of the action button Decrypt are as follows:

private void btnDecryptActionPerformed(java.awt.event.ActionEvent evt) {
char [] kode = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M' };
char [] abc = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

int ketemu=0;
char tampung = 0;
String plaintext = txtPlain.getText();
char[] ciphertext = new char[plaintext.length()];

if (!plaintext.equals(""))
txtPlain.setText(plaintext);

for(int w = 0; w
tampung = plaintext.toUpperCase().charAt(w) ;
for(int x = 0 ; x<=25 ; x++){
if(tampung == kode[x] ){
ketemu = x;
}
// else{ ketemu = -1; }
ciphertext[w] = abc[ketemu];
}

char bantu = 0;

bantu = abc[25];
// Pergeseran Index
for(int i = 25 ; i>=1 ; i-- ) {
abc[i] = abc[i-1];
}
abc[0] = bantu;
}
String c;
for(int w = 0; w txtCipher.setText(String.valueOf(ciphertext));
}

}

For the result, here is an example :
plain text = BEDA
chiper text = WYYR

keep trying and happy coding !

By : Mr.Stanza


Saturday, November 14, 2009

Introduction of JUGA (Java User Group Amikom)

The second meeting of Java User Group Amikom (JUGA) has been held in 4th building of STMIK AMIKOM Yogyakarta. As the speaker, Moh. Rizky Pratama(Tama, AMIKOM 07 Information Technology), the leader of JUGA, explained about the basic concept of Encapsulation as one chapter of Java Programming learning.

JUGA is one of many communities that existed in STMIK AMIKOM. This community is the place for the students of STMIK AMIKOM who want to learn and concentrate about Java Programming.

This community get big support from the lecturers and also the instituion of STMIK AMIKOM. Because we know that what we have got from lecture maybe not enough because knowledge Java Programming is so wide.

So if the students want to experience in Java Programming, they had to more explore about it. And JUGA, as the community, can be the alternative for it./MrStanza

Friday, October 23, 2009

How to Configure Path of Java on Windows

In this post, I assume that all of you have downloaded and installed Java Developement Kit (JDK 2.0 or above) . If java already installed on your computer but you still can’t use the command like ‘javac’ or ‘java’ on your command promt. Maybe you haven’t set the classpath of the java itself.

These are some ways to activate java command on your command prompt :

  1. First of all, make sure you have already installed JDK 2.0 that can be downloaded at www.java.sun.com free.
  2. And then, see at the address where you put the installed files. The default path is at C:\ C:\Program Files\Java\... After that, see where the bin folder exist.
  3. When you’re already active in C:\Program Files\Java\jdk1.6.0_10\bin, copy the address.
  4. And then, double click on My Computer, choose properties
  5. Activate the advanced tab, and click on environment variables.

  1. Find path or classpath or if they are not exist, you can create the new one with its name.


  1. Now, edit on the path or classpath. Type the semicolon (;), and then followed by paste the ‘C:\Program Files\Java\jdk1.6.0_10\bin’.


  1. Click OK, and now you can try the javac command on your command promt. Just try it! Java is so full of fun if you dare to love it.. J

TUGAS KELAS S1-SI-3I

1.Menampilkan nama, nim,kelas


2.Menghitung luas lingkaran dari variabel yang ditentukan


Digabung dalam satu file yang bernama tugas1_xxxx.java (4 digit nim)


Yang dikumpulkan adalah printout dari kode program dan preview output.


Dikumpulkan paling lambat tanggal 29 Oktober 2009. Kalau kesulitan atau ada yang ingin ditanyakan, silahkan ditanyakan. Bisa lewat facebook atau temui saya langsung. Sukses yah. :-)