Results 1 to 3 of 3
  1. #1
    syferite is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default How do I retrieve a input to another page?

    I am trying to display the user's name when the user registers in my program on the home page to say "Welcome ______" .

    I created a database, and created a entity class called Reg to store all the registered details such as Username, Password, Name, Email etc..

    My method was to :

    jLabelName.setText(r.getName() );

    and I also tried another one:

    if(r != null){
    jLabelName.setText(r.getName() );
    }

    Both didn't give me the result that I wanted.
    Is there another way to approach this?

  2. #2
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    are you sure the method r.getName( ) doesn't return an empty string?

  3. #3
    syferite is offline Member
    Join Date
    Oct 2009
    Posts
    7
    Rep Power
    0

    Default

    I think that may be the case.
    When I do my register, the output I get is ID = 0 on Access.

    Java Code:
    package sky.entity;
    
    import java.sql.ResultSet;
    import java.util.ArrayList;
    
    import sky.database.DBController;
    
    public class Reg {
    	
    private static int id;
    private String name;
    private String finic;
    private String email;
    private String username;
    private String password;
    private Object gender;
    private String contact;
    private Object age;
    
    public int getId() {
    	return id;
    }
    public void setId(int id) {
    	Reg.id = id;
    }
    public String getName() {
    	return name;
    }
    public void setName(String name) {
    	this.name = name;
    }
    public String getFinic() {
    	return finic;
    }
    public void setFinic(String finic) {
    	this.finic = finic;
    }
    public String getEmail() {
    	return email;
    }
    public void setEmail(String email) {
    	this.email = email;
    }
    public String getUsername() {
    	return username;
    }
    public void setUsername(String username) {
    	this.username = username;
    }
    public String getPassword() {
    	return password;
    }
    public void setPassword(String password) {
    	this.password = password;
    }
    public Object getGender() {
    	return gender;
    }
    public void setGender(Object gender) {
    	this.gender = gender;
    }
    public String getContact() {
    	return contact;
    }
    public void setContact(String contact) {
    	this.contact = contact;
    }
    public Object getAge() {
    	return age;
    }
    public void setAge(Object age) {
    	this.age = age;
    }
    
    public Reg() {
    	
    }
    
    public Reg(int regID, String regName, String regFinic, String regEmail, String regUsername, String regPassword, Object regGender, Object regAge, String regContact) {
    	
    }
    
    public Reg(String username, String password) {
    	this.username = username;
    	this.password = password;
    }
    
    public boolean createReg() {
    	
    	boolean success = false;
    	DBController db = new DBController();
    	db.setUp("myDatabase");
    	String sq1 = "INSERT INTO Reg (RegId, RegName, RegFinic, RegEmail, RegUsername, RegPassword, RegGender, RegAge ,RegContact) ";
    	sq1 += "VALUES (" + id + ", '" + name + "', '" + finic + "' , '" + email + "' , '" + username + "' , '" + password + "', '" + gender + "', '" + age + "' , '" + contact + "')";
    	
    if (db.updateRequest(sq1) ==1)
    		success = true;
    	db.terminate();
    	return success;
    }
    
    public boolean retrieveReg() {
    	
    	boolean success = false;
    	ResultSet rs = null;
    	DBController db = new DBController();
    	db.setUp("myDatabase");
    	String dbQuery = "SELECT * FROM Reg WHERE RegID = " + id;
    	rs = db.readRequest(dbQuery);
    	
    	try{
    		if(rs.next()) {
    			name = rs.getString("RegName");
    			finic = rs.getString("RegFINIC");
    			email = rs.getString("RegEmail");
    			username = rs.getString("RegUsername");
    			password = rs.getString("RegPassword");
    			gender = rs.getString("RegGender");
    			contact = rs.getString("RegContact");
    			age = rs.getString("RegAge");
    			success = true;
    		}
    	}
    	catch (Exception e) {
    		e.printStackTrace();
    	}
    	db.terminate();
    	return success;
    }
    
    public boolean updateReg() {
    	
    	boolean success = false;
    	DBController db = new DBController();
    	db.setUp("myDatabase");
    	String sq1 = "UPDATE Reg SET RegName = " + id + ", " + name +" , RegFINIC = '" + finic + "' , RegEmail = '" + email + "', RegUsername = '" + username + "', RegPassword = '" + password + "',RegAge = '" + age + "',RegGender = '" + gender + "', RegContact = " + contact;
    	
    	if (db.updateRequest(sq1)==1)
    		success = true;
    	db.terminate();
    	return success;
    }
    
    public boolean deleteReg() {
    	
    	boolean success = false;
    	DBController db = new DBController();
    	db.setUp("myDatabase");
    	String sq1 = "DELETE FROM Reg where RegID = " + id;
    	if (db.updateRequest(sq1)==1)
    		success = true;
    	db.terminate();
    	return success;
    	
    }
    
    public static ArrayList<Reg> getRegByCategory(){
    	ArrayList<Reg> RegList = new ArrayList<Reg>();
    	ResultSet rs = null;
    	DBController db = new DBController();
    	db.setUp("myDatabase");
    	String dbQuery = "SELECT * FROM Reg where RegID =  " +  id;
    	rs = db.readRequest(dbQuery);
    	try{
    		while (rs.next()){
    			int RegID = rs.getInt("RegID");
    			String RegName = rs.getString("RegName");
    			String RegFinic = rs.getString("RegFinic");
    			String RegEmail = rs.getString("RegEmail");
    			String RegUsername = rs.getString("RegUsername");
    			String RegPassword = rs.getString("RegPassword");
    			Object RegGender = rs.getObject("RegGender");
    			Object RegAge = rs.getObject("RegAge");
    			String RegContact = rs.getString("RegContact");
    			
    			
    			Reg Reg = new Reg (RegID, RegName, RegFinic, RegEmail, RegUsername, RegPassword, RegGender, RegAge, RegContact);
    			RegList.add(Reg);
    		}
    	}catch (Exception e) {
    		e.printStackTrace();
    	}
    	db.terminate();
    	return RegList;
    }
    
    }
    How do I make it so that the ID will be 1, 2, 3 etc..?
    I'm not sure whether this is the issue though :(

Similar Threads

  1. [SELENIUM] Retrieve the value of a hidden input type
    By gecko753 in forum Web Frameworks
    Replies: 1
    Last Post: 11-04-2009, 04:32 PM
  2. Replies: 1
    Last Post: 08-24-2009, 12:41 PM
  3. [SOLVED] retrieve the html code of any web page
    By Omarero in forum New To Java
    Replies: 3
    Last Post: 02-18-2009, 11:20 PM
  4. to retrieve multiple values from html page through jsp
    By raghu9198 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 02-17-2009, 03:43 PM
  5. to retrieve the webcontent from another page source
    By rameshsathasivam in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-25-2008, 09:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •