I am using struts2 and have a DAO class in that ,ve one authenticate method where i am getting a query from db.properties file. But my
question is how to get query data from xml file in to this method
instead of db.properties. Thanks in advance.
AuthenticateUser method
'Properties properties = new Properties();
InputStream inputStream = DBConnection.class.getClassLoader()
.getResourceAsStream("db.properties");
@Override
/** function authenticateUser
* @return UserBean
*/
public UserBean authenticateUser(UserBean userBean) throws SQLException,
NullPointerException {
// logger.info("connection establishing ");
// establishing connection
con = conn.createConnection();
userBean.setPassword(PasswordUtil.encryptPassword(userBean
.getPassword().toString()));
try {
properties.load(inputStream);
} catch (IOException e) {
System.out.println(e.getMessage());
}
String sql = properties.getProperty("users_signin_query");
// PreparedStatement is used to execute queries.
preparedstatement = con.prepareStatement(sql);
preparedstatement.setString(1, userBean.getUserName());
preparedstatement.setString(2, userBean.getPassword());
resultSet = preparedstatement.executeQuery();
UserBean bean = new UserBean();
if (resultSet.next()) {
bean.setIs_admin(resultSet.getString("is_admin"));
bean.setEmail(resultSet.getString("email"));
bean.setFirstname(resultSet.getString("first_name"));
bean.setUserid(resultSet.getString("id"));
bean.setMobile(resultSet.getString("mobile"));
bean.setUserName(resultSet.getString("username"));
bean.setLastname(resultSet.getString("last_name"));
bean.setPassword(resultSet.getString("password"));
return bean;
} else {
conn.close(con);
return bean;
}
}'
db.properties
jdbc details driver=com.mysql.jdbc.Driver db_url=jdbc:mysql://localhost:3306/app
Database Credentials
db_user_name=root db_password=root users_query=
insert into users(username,password,email,first_name,last_name,mobile,id)
values(?,?,?,?,?,?,?)*