Newer
Older
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Sonia Zorba <zorba at oats.inaf.it>
*/
private String hostname;
private int port;
private String username;
private String password;
public Credentials() {
super();
System.out.println("Credentials created");
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
this.port = 3306;
}
public String getHostname() {
return this.hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public int getPort() {
return this.port;
}
public void setPort(int port) {
this.port = port;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Connection getConnection() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace(System.err);
}
return DriverManager.getConnection(
"jdbc:mysql://" + this.hostname + ":" + this.port + "/",
this.username,
this.password
);
}
}