koneksi database dengan java


bikin database pake MySQL client…
tar di java baru bisa buat table (DDL & DML)…

konekin Java ke DB banyak caranya kk… diantaranya bisa lewat ODBCnya Windows atau langsung pake API JDBC…
gampangan si pake JDBC… tinggal taro tu file di JRE_DIR\lib\ext ama JDK_DIR\jre\lib\ext
trus cara panggilnya :

CODE
import java.sql.*;
class DBconnection
{
public Connection database_connection()
{
Class.forName(“org.gjt.mm.mysql.Driver”);
Connection conn = null;
conn = DriverManager.getConnection(“jdbc:mysql://localhost/<DB Name>”, “<MySQL User>”, “<MySQL Pass>”);
return conn;
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: