我正在使用Play framwork 1.2.5開發一個簡單的登錄應用程序,並建立了與本地postgres數據庫的連接;問題是試圖從數據庫中讀取inorder以驗證登錄信息和用戶是否匹配。處理本地postgres在播放框架中的數據1.2.5
的問題是我得到的URL空白頁:... /應用/登入而從簽到方式呈現的HTML頁應該輸出這樣的:TODO寫的內容
PS:我已上載JDBC驅動程序LIB
感謝
App/conf
# If you need a full JDBC configuration use the following :
db.url=jdbc:postgresql:postgres
db.driver=org.postgresql.Driver
db.user=postgres
db.pass=******
#
---------------------------------------------
the login page
<body>
#{form @Application.signIn()}
<form>
Online ID <input type="text" name ="onlineID" value="${onlineID}"><br>
Passcode <input type="text" name ="passcode" value="${passcode}">
<input type ="submit" value="Sign in">
</form>
#{/form}
</body>
---------------------------------------------
controller.App.java
public static void signIn(String onlineID, String passcode) {
login existing = new login(onlineID,passcode);
boolean verify=existing.check(existing.getOnlineID(),existing.getPassCode());
if(verify)
render("@Application.account");
}
---------------------------------------------
model.login.java
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import play.data.validation.*;
import play.db.DB;
public class login {
@Required public String onlineID;
@Required public String passcode;
public login(){}
public login(String onlineID,String passcode){
this.onlineID=onlineID;
this.passcode=passcode;
}
public void setOnlineID(String onlineID){
this.onlineID=onlineID;
}
public String getOnlineID(){
return this.onlineID;
}
public void setPassCode(String passcode){
this.passcode=passcode;
}
public String getPassCode(){
return this.passcode;
}
public boolean check(String onlineID,String passcode){
boolean verify=false;
Connection conn=null;
Statement stmt=null;
try{
conn = DB.getConnection();
stmt=conn.createStatement();
String sql;
sql="SELECT Cust_ID,password from corebanking.customer";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
int uID=rs.getInt("Cust_ID");
String ssn=rs.getString("SSN");
String pas=rs.getString("password");
String loginID=Integer.toString(uID);
if (onlineID.equals(loginID) && passcode.equals(pas)){
verify=true;
}
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
return verify;
}
}
---------------------------------------------
routes
GET / Application.index
GET / controllers.Application.signIn()
你爲什麼不使用jpa? –
謝謝。想測試本地postgres然後連接到雲postgres在heroku – user3189010
更新:這個應用程序處理數據時,我使用mysql而不是postgres – user3189010