Mehmet Ethem SULAN :: Struts Web Application Framework :: Struts Web Framework ile PostgreSQL Veritabanı Üye Kayıt (Action)
package www.ethemsulan.com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class KayitEtAction extends
        org.apache.struts.action.Action {
 public ActionForward execute(ActionMapping mapping,
    ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
//beanimizdeki degerleri aliyor.psotgresqle kaydediyor uygunsa.
BilgiGirActionForm benaimiz=(BilgiGirActionForm)form;
String kAd=benaimiz.getKulAd();
String kEm=benaimiz.getKulEmail();
String kPa1=benaimiz.getParola1();
 String kPa2=benaimiz.getParola2();
Class.forName("org.postgresql.Driver");
Connection baglanti=DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/postgres", "postgres", "ethemsulan");
Statement ifade=baglanti.createStatement();
//yanlis veri girilince kayit gerceklesmiyor ve BicimOner sayfasina gonderiliyor yanlis stringi sayesinde
if(!(kPa1.trim().equals(kPa2.trim())) | "".equals(kEm) |
  (kEm.indexOf("@")==-1) | "".equals(kAd)| "".equals(kPa1)){
 return mapping.findForward("yanlis");
        }
//dogru veri girilmise return mapping.findForward("basarili"); basarili stringine gore
//struts-config.xml deki forward ile Gerceklesti.jsp sayfaina yonlendiriyor.
//o sayfadanda bu beanimizdeki degerleri alip ekrana yaziyor
ifade.executeUpdate("insert into kisi(ad,email,parola)" +
        " values('"+kAd+"','"+kEm+"','"+kPa1+"') ");
return mapping.findForward("basarili");
    } }

Orj Kod:http://www.ethemsulan.pastebin.com/f48f7c
384

Write a Comment

Let me know what you think?