0

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

3
Contributors
6
Replies
42
Views
3 Years
Discussion Span
Last Post by Stefan_1
0

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();
        }


    }
0

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

0

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.

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.