
hi, I want to create a global connection file by using function like getConnection(),startConnection(), and stopConnection() etc. so anybody from my team can access that class file. can anybody help me out for the same.
Thanks in advance.

import java.sql.*;
class DatabaseConnection{
public static Connection getConnection() throws Exception {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String username = "root";
String password = "root";
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
}
public class GetConnection {
public static void main(String[] args) throws Exception {
Connection conn = DatabaseConnection.getConnection();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM data");
while(rs.next()){
System.out.println(rs.getString("name")+" \t "+rs.getString("address"));
}
rs.close();
st.close();
conn.close();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.