I have not used JDBC before. I want my program to store information from the user every time the user starts the program. Previous activity can be seen, so I have to use database, right?
So I thought of using JDBC but I have some problems.
import java.sql.* ;
public class Database {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/";
// Database credentials
static final String USER = "username";
static final String PASS = "password";
public Database(){
Connection con = null;
Statement stmt = null;
try{
Class.forName(JDBC_DRIVER);
}catch(Exception e){
e.printStackTrace();
System.exit(1);
}
try{
con = DriverManager.getConnection(DB_URL, USER, PASS);
}catch(Exception e){
e.printStackTrace();
System.exit(1);
}
}
}
ERROR : com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Caused by: java.net.ConnectException: Connection refused
- Where is this username and password used? In mysql installed on my laptop or does java have its own sql?
- Default username and password?
- If it is for mysql installed on my laptop, then what if I give my program to my friend to run and if he has a different username password for his mysql?