Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager;
- import java.sql.Statement;
- public class DatabaseConnection {
- Statement myStatHandle;
- public DatabaseConnection() {
- }
- public boolean connect() {
- try {
- // get an instance of the driver
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- // enter the details for your database user account
- String myUsername = "root";
- String myPassword = "pass";
- // the URL and DBMS for your database
- String myDatabaseURL = "jdbc:mysql://DATABASESERVER:3307/test";
- // get a connection to the database
- java.sql.Connection myDBConnection = DriverManager
- .getConnection(myDatabaseURL,myUsername,myPassword);
- // create a statement handle instance to carry out queries
- myStatHandle = myDBConnection.createStatement();
- // return true for successful connection
- return true;
- }
- catch (Exception E)
- {
- System.out.println(E.getMessage());
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement