package KONEKSI;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class tugas{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public void bukakoneksi(){
try{
Class a=Class.forName("com.mysql.jdbc.Driver");
System.out.println("OK "+a+" registered");
}catch(ClassNotFoundException ex){
JOptionPane.showMessageDialog(null,"Driver gagal dipanggil");
}
try{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/dealer_motor","root","");
stmt=conn.createStatement();
}catch(SQLException x){
JOptionPane.showMessageDialog(null,"Database tidak bisa dibuka");
}
}
public ResultSet getResultData(String query){
try{
rs=stmt.executeQuery(query);
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,"Error SQL 2"+ex.getMessage());
}
return rs;
}
public int manipulasiData(String query){
int jmlRecord=0;
try{
jmlRecord=stmt.executeUpdate(query);
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,"Error SQL 2"+ex.getMessage());
}
return jmlRecord;
}
public void tutupkoneksi(){
if(rs !=null){
try{
rs.close();
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,"Error SQL"+ex.getMessage());
}
}
}
}
Tidak ada komentar:
Posting Komentar