Hello im trying to connect database with my java program for register/login but im not doing well, i have online database on godaddy and i cannot connect with the java program i tryed with using the URLEncoder and it works for registering but for loging in i cannot make it please help me to connect it...
show me the code and i will just change the host, username and password ...
Thank you ! :)

Recommended Answers

All 6 Replies

Please someone help me ??? :/

You need to add .jar from mysql driver to your project and then just do like this...

public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("server adress","username","password");
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("querry");
            while(rset.next()) {
                // do what ever you want...
            }
            rset.close();
            stmt.close();
            conn.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }


    }

can u tell me what to add to my project and how do i do that ?

I work with this driver: "mysql-connector-java-5.0.4-bin"
When you download that in .jar extension you copy that in your project.
Then if you are using Eclipse you right click on it, from meni go to Build Path, Add to build Path. With that you add that library to your project.
Then you can add my code from last post, that code is for some select queries...
And you can do that if you are using MySql database, if you are using something else you need driver specific for that database and code can be different...

Class.forName("com.mysql.jdbc.Driver");

This hasn't been needed for years.

Stefan, read about how Java works. That's an extremely basic question. The driver jar needs to be on your classpath.

I have download that driver and place it into jre8 but now its showing me some error which is wierd com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Access denied for user 'StefanRafa'@'%' to database 'users' I have the right username and password but i dont know why the access is denied...

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.