Showing posts with label java community. Show all posts
Showing posts with label java community. Show all posts

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

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