package com.myapp.struts;
public class frmCari extends org.apache.struts.action.ActionForm {
private String kunci;
public String getKunci() {
return kunci;
}
public void setKunci(String kunci) {
this.kunci = kunci;
}
}
package com.myapp.struts;
import com.mysql.jdbc.Driver;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class actCari extends Action {
private final static String SUCCESS = "success";
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
java.sql.Driver d = new Driver();
String url = "jdbc:mysql://localhost:3306/namadatabase";
java.sql.Connection con =
DriverManager.getConnection(url, "userdatabase", "passworddatabase");
if (!con.isClosed()) {
//request.setAttribute("hasil","Terkoneksi");
con.setCatalog("DB");
frmCari fc = (frmCari) form;
Statement st = con.createStatement();
String query = "select * from database";
query += "where keterangan like '%"+ fk.getKunci() +"%'";
ResultSet rs = st.executeQuery(query);
//st.ex
String data="";
while(rs.next()){
data+=rs.getString("data ygmaudicari")+"
";
}
request.setAttribute("hasil",data);
rs.close();
con.close();
}
return mapping.findForward(SUCCESS);
}
}
No comments:
Post a Comment