Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:51:28+00:00 2026-06-17T23:51:28+00:00

i have a class which function is to validate the input to the database

  • 0

i have a class which function is to validate the input to the database befor it’s insert into the other database… it’s look like this :
1. Database Penduduk using oracle 9i
2. Database Pemohon using MySQL

here is the class i used to validate

this class is in data.KTP which is call Oracle 9i Database

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);
    }
}

}

and this one is from the other which is call from the above

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);
    }
}

}

Help me please…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:51:30+00:00Added an answer on June 17, 2026 at 11:51 pm

    public boolean CekNikPadaKtp(String nikPemohon) is an instance method in your KTP class and now you want to call it inside your class Pemohon

    then first you need to create an instance of KTP class and then invoke the method, like
     

     try{
     KTP k = new KTP(connection); // edited
     if (k.CekNikPadaKtp(tp.getKtpPemohon())) {
     ... remaining code....
    

    You cannot call an instance method of some other class without creating an instance/object of that class.

    I think you are not clear enough with classes, objects, instance methods, static methods, etc. and various other concepts in java.

    So better first clear these and then try, you will find it much easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which looks something like this, it returns a noncopyable class
I have following calss to validate my input elements. class Validator_FormValidator { public function
I have a class which has a function to retrieve children elements from a
I have a Login Class which has a function: isCorrect() that takes username and
I have a class ( EAGLView ) which calls a member function of a
I have a class with parse(int argc, char* argv[]) function which I have to
I have addFile function in my TableModel class which inserts a new record at
I have a relatively simple class which deletes a post: function delete_post($postid, $reason){ //Stuff
I have a Exception base class which defines a stream function: class Exception {
I have a class named toto which I send to a function that does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.