473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to write query for access session query with database

Expand|Select|Wrap|Line Numbers
  1. ResultSet res = st.executeQuery("select * from regist where Password='"+User_Password+"'");
  2.             if(res.next()==true)
  3.             {
  4.                 ps = con.prepareStatement("update regist set Password=?, Confirm_Password=? where Email_Id='"+session.getAttribute( "theEmail" )+"'");
  5.                 ps.setString(1, User_NewPassword);
  6.                 ps.setString(2, User_ConfirmPassword);
  7.                 ps.executeUpdate();
  8.                 con.close();
the above code i am write for maintain session and check condition. now i want to know am i write a right query or not. for DAO file bcoz i am write this code in java class file. and error is occur for session can not resolved
Mar 7 '12 #1
5 2698
r035198x
13,262 8TB
Did you declare session anywhere?
Don't tie your Http objects with your DAO classes. Your DAO should be reusable and testable without knowledge of your client type.
Make your method take the Email and password as String parameters.
Also, always close connections in a finally block.
Mar 7 '12 #2
hi r035198x first thanks for quick response.
and sir as u told last time i am now using the java class files for my jsp.
but how to use that declare session
tell me that little code.
Mar 7 '12 #3
r035198x
13,262 8TB
Call that DAO class from your controller (Servlet). In the servlet, you have access to the request, response and session objects.
Mar 7 '12 #4
changepassAction.jsp

String theEmail = session.getAttribute("theEmail").toString();

where i am declare the session in string varible.
and my DAO class file is,

changepassclass.java

String theEmail; //declare that again for use.

public String gettheEmail() {
return theEmail;
}
public void settheEmail(String theEmail) {
this.theEmail = theEmail;
}
//this is getter and setter for above declaration.

public String implement(){
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/registration","root","root");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("select * from regist where Password='"+User_Password+"'");
if(res.next()==true)
{
ps = con.prepareStatement("update regist set Password=?, Confirm_Password=? where Email_Id="theEmail,;");
ps.setString(1, User_NewPassword);
ps.setString(2, User_ConfirmPassword);
ps.executeUpdate();
con.close();
System.out.println("record-success.jsp");

//out.print("LOGIN Success");

}
else
{

// this is the condition where i want to check of that particulate user who's session is started..
plz tell me where i am wrong.
Mar 7 '12 #5
r035198x
13,262 8TB
Java is object oriented. Think objects and stop doing everything in one file. It's really bad code. Create classes
Expand|Select|Wrap|Line Numbers
  1. class User {
  2.     private String email;
  3.     private String password;
  4.     public User(String email, String password) {
  5.     super();
  6.     this.email = email;
  7.     this.password = password;
  8.     }
  9.     public String getEmail() {
  10.         return email;
  11.     }
  12.     public void setEmail(String email) {
  13.         this.email = email;
  14.     }
  15.     public String getPassword() {
  16.         return password;
  17.     }
  18.     public void setPassword(String password) {
  19.         this.password = password;
  20.     }
  21.  
  22.  
  23. }
  24.  
  25. class DAO {
  26.  
  27.     public User getUser(String email) {
  28.     // Select from DB and create a user object and return that
  29.     }
  30.     public boolean changePassword(String email, String password) {
  31.     //do your update statement here
  32.     }
  33. }
  34.  
Then your JSP doesn't contain process code anymore. It just asks for data from the DAO.
Mar 7 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Smith | last post by:
I wrote a VB6 application wich uses the jet dbengine and access 97 db formats in the database and crystal reports to generate reports on the data. When it is run on windows 95,98,ME it works fine,...
0
by: totierne | last post by:
comp.databases.ms-access, I want to know how to use Oracle views with session variables in Access. The parameterised views in access, are migrated to views with per session variables. The...
1
by: hulinning | last post by:
Hi I use webservice to read/write data to Access database using System.Data.OleDb with a connection string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source;User Id=admin;Password=" I can...
2
by: scott.alfon | last post by:
Hello, i need your help. I want to implement a php-script where I can access to different database types as PostSQL, MySQL etc. Is that possible? Furthermore I want to include an access...
6
by: DNB | last post by:
I would like to know what you guys think is the best way to access data: Asp.Net session vs. Database Queries. In our application we are using asp.net tree view to display hierarchical data and...
3
by: DNB | last post by:
I did post this message in C# group also... I would like to know what you guys think is the best way to access data: Asp.Net session vs. Database Queries. In our application we are using...
1
by: in10se | last post by:
I have the following code in my global.asax file: void Application_Error(object sender, EventArgs e) { string ex = Server.GetLastError().ToString(); HttpContext.Current.Session =...
10
by: teddysnips | last post by:
My clients have asked me to maintain a database that was developed in- house. It's pretty good, considering the developer isn't a "programmer". The first thing they want me to do is to split it...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
1
by: Jacques Franken | last post by:
Hello everybody; First of all, I'm a newby in generating SQL code. I'm trying to generate a query on a MSSQL database using Access 2007. I need to query a table on a DATE/TIME field. The problem...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.