0% found this document useful (0 votes)
30 views8 pages

J2ee 2

This document provides instructions for connecting a Java application to a MySQL database. It describes creating a database called "dbmahasiswami" with a table called "tbMahasiswa" to store student data. It also explains how to set up a DSN in ODBC to connect to the database using the connection string "jdbc:odbc:mahasiswami". Sample code is given to import the necessary Java libraries, get a connection object, and test the connection by printing success or failure messages. The instructions conclude by noting the code should be put in a class file and deployed using a tool before checking the connection in a browser.

Uploaded by

Reza Muhamad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views8 pages

J2ee 2

This document provides instructions for connecting a Java application to a MySQL database. It describes creating a database called "dbmahasiswami" with a table called "tbMahasiswa" to store student data. It also explains how to set up a DSN in ODBC to connect to the database using the connection string "jdbc:odbc:mahasiswami". Sample code is given to import the necessary Java libraries, get a connection object, and test the connection by printing success or failure messages. The instructions conclude by noting the code should be put in a class file and deployed using a tool before checking the connection in a browser.

Uploaded by

Reza Muhamad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

J2EE (Enterprise Programing)

KONEKSI DATABASE
Database DSN Coding java Convert ke class Deploy tools Cek di Browser

Membuat Database
Buat database dbmahasiswami yang di dalamnya terdapat 1 tabel :
tbMahasiswa

FIELD
Nim Nama

TYPE
Varchar (8) Varchar (20)

KETERANGAN
Primary key

Alamat

Varchar (30)

Membuat DSN
Buka Control Panel >> Administrative Tools >> Data Sources (ODBC) Pada tab User DSN
Pilih Add >> MySQL ODBC 5.1 Driver Data Source Name = mahasiswami Server = localhost User = root

Coding Koneksi (1)


import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class koneksi extends HttpServlet{ PrintWriter out=null; Connection con=null; ResultSet rs=null; public void service (HttpServletRequest rq, HttpServletResponse rs) throws ServletException, IOException{ out=rs.getWriter();

Coding Koneksi (2)


try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:mahasiswami","root",""); out.println("Koneksi Berhasil"); } catch(Exception e){ out.println (e.toString()); out.println("Koneksi Gagal"); }

}
}

Ubah coding koneksi ke file class Jalankan di deploytool Cek koneksi di browser anda

TERIMA KASIH

You might also like