SQL Adapter di Netbeans

sebenarnya, apa sih SQL Adapter itu????

The SQL adapter menjadi perantara untuk pertukaran data antara Java and a SQL Server database. kamu bisa menggunakan SQL adapter untuk insert, update, and delete data di SQL Server tables dengan menggunakan SQL updategrams atau lewat invoking stored procedures.

Source code SQL Adapter di Netbeans

package nordersystem;

import java.sql.*;
import java.util.*;

/**
*
* @author user
*/
public class SQLAdapter extends javax.swing.JPanel {

public String HostName;
public String UserName;
public String UserPassword;
public String UserDatabase;
public String UserQuery;
//database
public String url;
public Connection con;
public Statement stmt;
public Statement stmt1;
public String Driver;
public ResultSet rs;
public ResultSet rs1;
public ResultSetMetaData rsmd;
public ResultSetMetaData rsmd1;

/** Creates new form SQLAdapter */
public SQLAdapter() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
// <editor-fold defaultstate=”collapsed” desc=”Generated Code”>
private void initComponents() {

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
// Variables declaration – do not modify
// End of variables declaration

public void Connect() {
try {
Class.forName(Driver);
} catch (java.lang.ClassNotFoundException e) {
System.err.print(“ClassNotFoundException: “);
System.err.println(e.getMessage());
}

try {
con = DriverManager.getConnection(url, UserName, UserPassword);
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(UserQuery);
rsmd = rs.getMetaData();
} catch (SQLException ex) {
System.err.println(“SQLException: ” + ex.getMessage());
}
}

public void Requery(String statementStr) throws SQLException {
try {
stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

rs1 = stmt1.executeQuery(statementStr);
rsmd = rs1.getMetaData();
} catch (SQLException ex) {
System.err.println(“SQLException: ” + ex.getMessage());

}/*
stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

rs1 = stmt1.executeQuery(statementStr);
//rsmd = rs1.getMetaData();*/
}

public void CloseConnection() {
try {
rs.close();
con.close();
} catch (SQLException ex) {
System.err.println(“SQLException: ” + ex.getMessage());
}
}
// Variables declaration – do not modify
// End of variables declaration
}

Advertisements