Hello guys im working on program and i stucked at database i need to create some place that will save all information of Account (in some file if can) then read it every time user "Log in" in the program. I tryed searching but i cant get it ...
Please someone show me exsample and give some code i will be very happy thanks. :)
I need it fast :/
And i forget the reader to read from the textfields like UserName and Password

Recommended Answers

All 21 Replies

PLEASE SOMEONE HELP ME IF YOU DONT UNDERSTAND JUST TELL :S

dude i realy dont need to be online just create a file and tupe the info in it then read it when user want to log in just a simple login system using ur pc as data base if can

JDBC does not require online connection. you need to establish a database connection, so that u can write or read in your database.

you can try this code.
Here I have used the file newfile.txt which is stored in the following location
C:\Documents and Settings\Administrator\WebApplication4\web\WEBINF\data\newfile.txt
So don't get confuse with this.

/*
 * writedata.java
 *
/

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;


public class writedata extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
       File f=new File("C:\\Documents and Settings\\Administrator\\WebApplication4\\web\\WEB-INF\\data\\newfile.txt");
       PrintWriter pw=new PrintWriter(new FileWriter(f,true));
       pw.println(request.getParameter("hello")+'\t');

       pw.flush();

       File fr=new File("C:\\Documents and Settings\\Administrator\\WebApplication4\\web\\WEB-INF\\data\\newfile.txt");
    FileReader frr=new FileReader(fr);
    BufferedReader br=new BufferedReader(frr);
     String data=br.readLine();

       out.println("<html>");
       out.println("<head>");
     out.println("<title>Servlet writedata</title>");
        out.println("</head>");
        out.println("<body>");
          while(data!=null)
          {
                out.println(data);
                data=br.readLine();
          }
        out.println("</body>");
       out.println("</html>");

        out.close();
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}

DO tell me if it worked or not?

The code i have provided to u is only for writting on a file .

where to put this dude i dont get it ...
do you have something to contact you facebook, skype, msn, google+ ?? :/

commented: I don't like your tone. -3

@StefanRafa0
Okay...

@stefanRafa0
Perhaps you have not read the member rules of DaniWeb Community.There is a clear mention that it is not your chatroom where you are talking to your friends by calling them "dudes". Everybody here is much experienced than any other. So. next time do not repeat this mistake.

Now, In regards to your problem, You do not need to put this anywhere in existing code.
This web page will be the link to the main page in which you have made username/password fields.
As the submit button of that page will be clicked by the user, he will get linked to this page in the back end. And the respected entries from him will be written on file newfile.txt

all right sorry for my mistake but i realy need help with this cause i i have watched many tutorials and cant figure out :/
- So here is my email addres if you want to contact me: <snip>

@StefanRafa0
Its Okay.. :)
And please feel free to tell your problem.
Or you may send the code that you have tried so far so that I can modify it to get the desirable result.

my email ID is <address removed>

JFrame Form: NewAccount.java ( users can create a new passwords )

private void CreateButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        try {
            String newAccount = NameOfAccountTextBox.getText();
            FileWriter NewAccount = new FileWriter("NewAccountInfo.txt");
            BufferedWriter out = new BufferedWriter(NewAccount);
            out.write(newAccount);
            out.close();
        } catch (Exception ex) {
        }
        try {
            String Username = UserNameTextBox.getText();
            FileWriter NewAccount = new FileWriter("NewAccountInfoUsername.txt");
            BufferedWriter out = new BufferedWriter(NewAccount);
            out.write(Username);
            out.close();
        } catch (Exception ex) {
        }
        try {
            String password = PasswordTextBox.getText();
            FileWriter NewAccount = new FileWriter("NewAccountInfoPassword.txt");
            BufferedWriter out = new BufferedWriter(NewAccount);
            out.write(password);
            out.close();
        } catch (Exception ex) {
        }
        InfoLabel.setText("Account created succesfuly !");
    }

JFrame Form: NewUser.java ( to create a new acccount in the program )

private void CreateButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        try {
            String username = TextBoxCreateUserName.getText();
            FileWriter NewUser = new FileWriter("NewUserInfoUserName.txt");
            BufferedWriter out = new BufferedWriter(NewUser);
            out.write(username);
            out.close();
        } catch (Exception ex) {
        }
        try {
            String password = TextBoxCreatePassword.getText();
            FileWriter NewUser = new FileWriter("NewUserInfoPassword.txt");
            BufferedWriter out = new BufferedWriter(NewUser);
            out.write(password);
            out.close();
        } catch (Exception ex) {
        }
        InfoLabel.setText("User created succesfuly !");
    }

JFrame Form: Stefan.java :D ( the main form and the login Panel )

private void EnterActionPerformed(java.awt.event.ActionEvent evt) {                                      
        String password = paswTxt.getText();
        String username = usrTxt.getText();
        if (username.equals("Stefan") && "0000".equals(password)) {
            Label.setText("Acepted");
            UserInfo userinfo = new UserInfo();
            userinfo.setVisible(true);
        } else {
            Label.setText("Declined");
        }
    }

JFrame Form: UserInfo.java ( this is mine and ill delite it if needed )

private void EnterButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        if ("vip".equals(Name.getText().trim()) || "Vip".equals(Name.getText().trim()) || "VIP".equals(Name.getText().trim())) {
            TextBox1.setText("StefanRafa");
            TextBox2.setText("0000");
            Label.setText(" ");
        } else {
            Label.setText("Unknown Request !");
            TextBox1.setText("Empty !");
            TextBox2.setText("Empty !");
        }
        if ("profit clicking".equals(Name.getText().trim()) || "PROFIT CLICKING".equals(Name.getText().trim()) || "Profit Clicking".equals(Name.getText().trim()) || "profit".equals(Name.getText().trim())) {
            TextBox1.setText("2129027");
            TextBox2.setText("0000");
            Label.setText(" ");
        }
        if ("youtube".equals(Name.getText().trim()) || "YouTube".equals(Name.getText().trim()) || "YOUTYBE".equals(Name.getText().trim()) || "you tube".equals(Name.getText().trim())) {
            TextBox1.setText("StefanRafaa@gmail.com");
            TextBox2.setText("0000");
            Label.setText(" ");
        }
        if ("Gmail".equals(Name.getText().trim()) || "gmail".equals(Name.getText().trim()) || "GMAIL".equals(Name.getText().trim()) || "GMail".equals(Name.getText().trim()) || "GmaiL".equals(Name.getText().trim())) {
            TextBox1.setText("StefanRafaa@gmail.com");
            TextBox2.setText("0000");
            Label.setText(" ");
        }
        if ("FaceBook".equals(Name.getText().trim()) || "Facebook".equals(Name.getText().trim()) || "FACEBOOK".equals(Name.getText().trim()) || "facebook".equals(Name.getText().trim())) {
            TextBox1.setText("StefanRafaa@gmail.com");
            TextBox2.setText("0000");
            Label.setText(" ");
        }
    }

This project is maked in netbeans and i the last one "JFrame Form: UserInfo.java" is just for testing does will work so i will delite that just to learn how to read it from ".txt" files if is possible ...
Thanks all :)

Okay ..Click this,it will help u for sure. :)

Need someone to show me please i cant do it alone .. :S
If you guys need pictures i will take a screenshot of the project ...

why this doesnt work ???

try{
            File p = new File("NewUserInfoPassword.txt");
            File u = new File("NewUserInfoUserName.txt");
            FileReader fr = new FileReader(u);
            FileReader fr1 = new FileReader(p);
            int ch = fr.read();
            int ch1 = fr1.read();
            if(u.equals(usrTxt) && p.equals(paswTxt)){
                UserInfo userinfo = new UserInfo();
                userinfo.setVisible(true);
            }else{
                Label.setText("undone !");
            }
        } catch (Exception ex) {
        }

Always printing "undone !"
Thanks

Stefan

 File p = new File("NewUserInfoPassword.txt");
 File u = new File("NewUserInfoUserName.txt");

Have you mentioned the full path of your textfiles in the code.????
If yes, then where it is?
And now it is being funnier that you are comparing a file with textfield data!!

So let me get this straight:

You want a form that you can login or register.
If you register, it asks you to put a username, password and (for example) telephone, address, email, etc
If you login, it shows you your telephone, address, email, etc....

All this information is stored in a file. What kind of file: text, csv, xml, etc?

Correct?

@ stefan
As you wanted the step by step procedure for making connection to Oracle10g XE, I am hereby giving the procedure. But before using this , you must know how to execute basic SQL statements for creating table, Inserting values in it and Retrieval of values from the table.

  1. GO to DB homepage
  2. Make your Login
  3. Click on SQL
  4. Click on SQL Commands.
  5. Create tables and execute other queries.

for more details Click
Otherwise you can simply use MS Acess

i dont know how to create tables in sql but i have make account hope u will come to help me i send you email ... :)

i dont know how to create tables in sql but i have make account hope u will come to help me i send you email ... :)

Congratulations, you just limited your chances of getting good advices.
In this context email is far less productive to get answers than a forum is.
On a forum people will correct each other when one gets it wrong, you'll be confronted with different point of views, different opinions about a subject.
Moreover on a forum sharing of knowledge is encouraged, everything that gets written here may potentially be useful to other people in the future.
People here are not clairvoyant and cannot read emails sent between you and someone else, they can't see which things have been suggested already, and which haven't, what worked, and what didn't.
I hope you take that into consideration next time you decide to take such an action.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.