2012-08-03 6 views
-1

사용자가 postgres db에 있는지 확인하고 로그인 할 수있는 로그인 페이지를 개발하는 프로젝트가있었습니다. 그렇지 않으면 새 사용자로 로그인하도록 요청합니다. if 절도 입력했습니다. 하지만 작동하지 .... 내 코드는wicket 로그인 페이지와 데이터베이스 연결

enter code here 

package in.login; 

import java.sql.Connection; 

public class Page3 extends WebPage{ 

    public Page3(){ 
     final TextField uname = new TextField("uname", new Model()); 
     final TextField password = new PasswordTextField("password", new Model()); 
     add(new FeedbackPanel("feedback")); 

     Form form = new Form("f"){ 
      protected void onSubmit() { 
       String v1= uname.getDefaultModelObjectAsString(); 
       String v2 = password.getDefaultModelObjectAsString(); 
       System.out.println(uname.getDefaultModelObjectAsString()); 
       System.out.println(password.getDefaultModelObjectAsString()); 
       try { 

        Class.forName("org.postgresql.Driver"); 
        Connection conn = DriverManager.getConnection(
          "jdbc:postgresql://localhost/registration:5432", 
          "postgres", 
          "ashneel"); 
        try { 
         conn.setAutoCommit(false); 
         PreparedStatement st = (PreparedStatement) conn.prepareStatement("select * from registration where uname='"+v1+"' and password='"+v2+"' "); 
         try{ 
          if(password.equals(v2)) { 
           System.out.print("aaaaa"); 
           setResponsePage(Inbox.class); 
          } 
          else { 
           System.out.print("new user"); 
          } 
          setResponsePage(Inbox.class); 
         } finally { 
          st.close(); 
         } 
        } catch (Exception e) { 
         conn.rollback(); 
         throw e; 
        } 

       } catch (Exception e) { 
        throw new RuntimeException(e); 
       } 

      } 

     }; 

     form.add(uname); 
     password.add(StringValidator.minimumLength(5)); 
     password.add(StringValidator.maximumLength(10)); 
     form.add(password); 
     add(form); 

     form.add(new Link("link") { 
      public void onClick() { 
       Registr registr = new Registr(); 
       setResponsePage(registr); 
      } 
     }); 
    } 
} 
+0

작동하지 않는 그것의 어떤 부분? 스택 트레이스를 얻었습니까? 컴파일 될까요? – Makoto

+0

'wicket-auth-roles'을 사용하고 있습니까? 'Application' 클래스가'AuthenticatedWebApplication'을 확장합니까? – tetsuo

답변

1

당신은 사용해야합니다 - 이것도 :

PreparedStatement st = (PreparedStatement) conn.prepareStatement("select * from registration where uname=? and password=? "); 
st.setString(1,v1); 
st.setString(1,v2); 
ResultSet rs=st.executeQuery(); 
if(rs.next()){ 
          System.out.print("aaaaa"); 
}else{ 
          System.out.print("new user"); 
}