wallet123 15 Junior Poster

What u need is an organize code :)

In establishing a connection with you database
i think this is a more better way.

The code below shows how to connect or establish a connection.
as you can see, it is organized in a way that if you miss something, you will easily notice it.

Here are the steps:
1. Create a new class.
2. Study the code below and try to analyse it.

    public Connection getConnection() {
        final String USER_NAME  ="You Username";
        final String PASSWORD = "Your Password";
        final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        final String JDBC_URL = "jdbc:mysql://localhost:3306/Your schema ";

        Connection conn = null;

        try{
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection(JDBC_URL, USER_NAME, PASSWORD);
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }catch(SQLException e){
            e.printStackTrace();
        }
        return conn;
    }

}

After that you can now create your servlet.
Here's how :
1. Create a new class, and put it in a package named: "app.servlet"
You should put all ur servlet classes in an app.servlet package so that it will be easy for you to look for things.

  1. Our professor said that it is not neat to print from a servlet class. So dont do that. A servlet class should only be a servlet class, and not do anything that is not its purpose.

  2. Create another class. The class that you should create is a class that will write into your database.

    How should you write your servlet:

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    
           
JamesCherrill commented: Excellent teaching post +15
wallet123 15 Junior Poster

Reading through this thread, and having seen your past threads, you learnt a lot while writing this program correct? and as you learn you just added, and it happens even to the best of us when something starts going wrong you dont know where to look because you dont understand the main logic of your program and what its busy doing at its different stages and inputs..

I would suggest by instead of revision which you have been trying, why not re-write it, of course using what you've now learnt and of course some copying and pasting of your own code where relevant-not only do i assure you, you will find the error you will write more logical and comprehensible code that you can easily track errors in and your lecturer will understand it and know you do too. This could include adding methods inside the if or case statements to break the code into sections , and have proper error checking etc

hey i have re-written my code, and little by little, i can see that now im a bit organized thanks!!! now the codes are working properly thank you!

wallet123 15 Junior Poster

and, as soon as you inputted it, that value is the original number I was talking about :)

ok i understand ..what i did not understand is this part:

and print this number following by the word 'thousand'
you subtract this number (*1000, off course) from your original number and do the same for hundreds, ..

after that, you check how to link the words to the numbers, but as you can see above, all you need for words is one to nineteen and ten to ninety, since above that, it is one hundred