Here my web service..
package ahsanfile.webservice;
import ahsanfile.webservice.util.DataBase;
import ahsanfile.webservice.model.Karyawan;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
*
* @author Master
*/
@WebService()
public class DataKaryawan {
/**
* Web service operation
*/
@WebMethod(operationName = "getKaryawan")
public List<Karyawan> getKaryawan() {
List<Karyawan> lk = new ArrayList<Karyawan>();
DataBase db = new DataBase();
try {
String sql = "select * from tbl_karyawan";
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Karyawan karyawan = new Karyawan();
karyawan.setErrorMessage("");
karyawan.setIdKaryawan(rs.getInt("id_karyawan"));
karyawan.setNamaKaryawan(rs.getString("nama_karyawan"));
karyawan.setAlamatKaryawan(rs.getString("alamat_karyawan"));
karyawan.setEmailKaryawan(rs.getString("email_karyawan"));
karyawan.setTeleponKaryawan(rs.getString("telepon_karyawan"));
lk.add(karyawan);
}
return lk;
} catch (Exception e) {
Karyawan karyawan = new Karyawan();
karyawan.setErrorMessage(e.getMessage());
lk.add(karyawan);
return lk;
} finally {
db.closeConnection();
db = null;
}
}
/**
* Web service operation
*/
@WebMethod(operationName = "cariKaryawan")
public List<Karyawan> cariKaryawan(@WebParam(name = "namKaryawan")
final String namKaryawan) {
List<Karyawan> lk = new ArrayList<Karyawan>();
DataBase db = new DataBase();
try {
String sql = "select * from tbl_karyawan where nama_karyawan like ?";
PreparedStatement ps = db.getConnection().prepareStatement(sql);
ps.setString(1, "%" + namKaryawan + "%");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Karyawan karyawan = new Karyawan();
karyawan.setErrorMessage("");
karyawan.setIdKaryawan(rs.getInt("id_karyawan"));
karyawan.setNamaKaryawan(rs.getString("nama_karyawan"));
karyawan.setAlamatKaryawan(rs.getString("alamat_karyawan"));
karyawan.setEmailKaryawan(rs.getString("email_karyawan"));
karyawan.setTeleponKaryawan(rs.getString("telepon_karyawan"));
lk.add(karyawan);
}
return lk;
} catch (Exception e) {
Karyawan karyawan = new Karyawan();
karyawan.setErrorMessage(e.getMessage());
lk.add(karyawan);
return lk;
} finally {
db.closeConnection();
db = null;
}
}
}