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 ! :)

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

public static void main(String[] args) {
        try {
            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...
        catch (Exception e) {


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...


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...

This article has been dead for over six months. Start a new discussion instead.