Cara mengecek koneksi ODBC/JDBC
Sebelum melakukan insert update delete pada program buatan alangkah baiknya kita melakukan tes koneksi,supaya kita tahu apakah Driver ODBC-JDBC kita terkoneksi,ni source code nya :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.*;
import javax.swing.*;
/**
*
* @author matt
*/
public class teskoneksi
{
void conn()
{
try
{
String dbname="jdbc:odbc:database2";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(dbname,"matt","matt");//user & pasword
JOptionPane.showMessageDialog(null,"connection succes","Insert data",JOptionPane.INFORMATION_MESSAGE);
con.close();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e,"gagal",JOptionPane.WARNING_MESSAGE);
}
}
public static void main (String[]args)
{
teskoneksi test = new teskoneksi();
test.conn();
System.exit(0);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.*;
import javax.swing.*;
/**
*
* @author matt
*/
public class teskoneksi
{
void conn()
{
try
{
String dbname="jdbc:odbc:database2";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(dbname,"matt","matt");//user & pasword
JOptionPane.showMessageDialog(null,"connection succes","Insert data",JOptionPane.INFORMATION_MESSAGE);
con.close();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e,"gagal",JOptionPane.WARNING_MESSAGE);
}
}
public static void main (String[]args)
{
teskoneksi test = new teskoneksi();
test.conn();
System.exit(0);
}
}
Komentar
Posting Komentar