我有一个类,它的功能是在将输入插入另一个数据库之前验证数据库的输入......它看起来像这样:1. 使用 oracle 9i 的数据库 Penduduk 2. 使用 MySQL 的数据库 Pemohon
这是我用来验证的类
此类在称为 Oracle 9i 数据库的 data.KTP 中
public class KTP {
public KTP (){
}
private Connection connection;
private String sql;
public KTP(Connection connection) {
this.connection = connection;
}
public boolean CekNikPadaKtp(String nikPemohon) throws Exception {
PreparedStatement ps = null;
try {
boolean cekNik = true;
String nikKtp = "";
sql = "SELECT NIK, TGL_BERLAKU FROM SIAKOFF.VW_KTP_WNI A, DUAL B "
+ "where TGL_BERLAKU < to_char(sysdate, 'DD-MM-YYYY') AND NIK=?";
ps = connection.prepareStatement(sql);
ps.setString(1, nikPemohon);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
nikKtp = rs.getString("nik");
}
rs.close();
if (nikKtp.equals("")) {
cekNik = false;
}
return cekNik;
} finally {
ConnectionUtil.closePreparedStatement(ps);
}
}
}
这个是从上面调用的另一个
public class Pemohon {
private Connection connection;
private String sql;
public Pemohon(Connection connection) {
this.connection = connection;
}
public String savePemohon(TblPemohon tp) throws Exception {
PreparedStatement ps = null;
try {
if (CekNikPadaKtp(tp.getKtpPemohon())) {
sql = "insert into pemohon"
+ "(noktp_pemohon,nama_depan,nama_belakang,tempat_lahir_pemohon,tgl_lahir_pemohon,sex,"
+ "agama,status_perkawinan,pekerjaan_pemohon,nama_jalan_pemohon,rt_pemohon,rw_pemohon,kelurahan_pemohon,"
+ "kecamatan_pemohon,kab_ko_pemohon,provinsi_pemohon,pos_pemohon,telp_pemohon,kewarganegaraan_pemohon) "
+ "values("
+ "?,?,?,?,?,"
+ "?,?,?,?,?,"
+ "?,?,?,?,?,"
+ "?,?,?,?,?)";
ps = connection.prepareStatement(sql);
ps.setString(1, tp.getKtpPemohon());
ps.setString(2, tp.getNamaDepanPemohon());
ps.setString(3, tp.getNamaBelakangPemohon());
ps.setString(4, tp.getTempatLahirPemohon());
ps.setString(5, tp.getTanggalLahirPemohon());
ps.setString(6, tp.getJenisKelamin());
ps.setString(7, tp.getAgamaPemohon());
ps.setString(8, tp.getStatusPerkawinan());
ps.setString(9, tp.getPekerjaanPemohon());
ps.setString(10, tp.getNamaJalanPemohon());
ps.setString(11, tp.getRtPemohon());
ps.setString(12, tp.getRwPemohon());
ps.setString(13, tp.getKelurahanPemohon());
ps.setString(14, tp.getKecamatanPemohon());
ps.setString(15, tp.getKabupatenPemohon());
ps.setString(17, tp.getProvinsiPemohon());
ps.setString(18, tp.getKodePosPemohon());
ps.setString(19, tp.getTelpPemohon());
ps.setString(20, tp.getKewarganegaraanPemohon());
ps.execute();
return "success";
} else {
return "Info : nik pemohon belum ada di tabel ktp !";
}
} finally {
ConnectionUtil.closePreparedStatement(ps);
}
}
}
请帮帮我...