Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- public class Handler {
- private String address="";
- private String username="";
- private String password="";
- private String databaseName="";
- public Handler(String address, String username, String password, String databaaseName) {
- this.address = address;
- this.username = username;
- this.password = password;
- this.databaseName = databaaseName;
- }
- public Handler(String address, String username, String password) {
- this.address = address;
- this.username = username;
- this.password = password;
- }
- public String getAddress(){
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public String getUsername() {
- return username;
- }
- public String getPassword() {
- return password;
- }
- public String getDatabaseName() {
- return databaseName;
- }
- /*
- public boolean connect() throws SQLException{
- Connection conn=null;
- String uri="";
- uri="jdbc:mysql://"+this.getAddress()+"/"+this.getDatabaseName()+"?user="+this.getUsername()+"&password="+this.getPassword();
- try {
- //Do something with the connection
- conn = DriverManager.getConnection(uri);
- return true;
- }catch(SQLException ex ){
- //Catch errors
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- return false;
- }
- }
- */
- public static void main(String[] args){
- Connection conn = null;
- String uri = "";
- uri = "jdbc:mysql://"+this.getAddress()+"/"+this.getDatabaseName()+"?user="+this.getUsername()+"&password="+this.getPassword();
- try {
- conn = DriverManager.getConnection(uri);
- }catch(SQLException ex ){
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- }
- Statement stmt = null;
- ResultSet rs = null;
- try{
- stmt=conn.createStatement();
- if (stmt.execute("SELECT FROM ")) {
- rs = stmt.getResultSet();
- }
- }catch (SQLException ex){
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- }
- }
- }
Add Comment
Please, Sign In to add comment