This is my db class for my JavaSE application.
public class db {
static Connection c;
public static Connection Get_Connection() throws ClassNotFoundException,SQLException {
if (c == null) {
String ip = "";
String port = "";
String username = "";
String password = "";
try {
BufferedReader br = new BufferedReader(new FileReader(System.getProperty("user.home") + "/ConnectionSettings.txt"));
ip = br.readLine();
port = br.readLine();
username = br.readLine();
password = br.readLine();
br.close();
} catch (Exception e) {
e.printStackTrace();
}
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://" + ip + ":"+port + "/mydb", username, password);
}
return c;
}
I know this isn't a good practice. I'm getting IP address, database password and port from a text file saved in C:/..
.
My question is, if I want to network the project is it okay to provide IP address of server machine in this db class?
If not tell me why, and how to network JavaSE applications?
It's okay if you provide answers in links.
What are the frameworks I should be using to network the applications?
Will hibernate
be a solution for this?