JDBC/Java App Port Scanning?

162 views Asked by At

I'm having problems with my host as I keep on getting blocked for Port Scanning. Even though they have been whitelisting me, my IP is dynamic, so that's not really a solution.

I've been checking and the only 2 apps I use to connect directly to my MySQL db in the host are MySQL Workbench and the app I'm developing. I'm guessing MySQL Workbench is not the one doing the port scanning, as I'm explicitly asking it to connect to port 3306.

On the other hand, the app I'm making doesn't seem to connect directly to the port. I was under the understanding that JDBC did this automatically but it isn't doing so app. Therefore, my question is, how can I make my app point directly to port 3306?

It's also possible that my app is not the one responsible for the port scanning and it's something else, however, I can figure out what. I do not use any kind of security software.

BTW, on the try/catch I do in my connection I make the catch connect the db to my localhost so that I can continue working and testing my app.

This is my code:

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.JButton;

import Controller.utilidadesGenericas;
import Objetos.Generos;
import Objetos.Tema;
import Objetos.Usuario;
import Objetos.Videojuego;
import View.errorPopUp;

public class database {

    protected Connection conexion;
    protected Statement statement;

    protected static String schema = "federicoanelli_S"; 
    private static String host = "67.222.1.89";
    private static String user = "federicoanelli_S";
    private static String pass = "(PASSWORD HERE)";
    private static String servidor = "jdbc:mysql://"+host+"/" + schema;

    //protected static String schema = "Streamz";
    //private static String user = "root";
    //private static String pass = "";
    //private static String servidor = "jdbc:mysql://localhost/" + schema;


    public database() {
        this.init();
    }

    public void init() {

        try {
            Class.forName("com.mysql.jdbc.Driver");//com.mysql.jdbc.Driver
            conexion = DriverManager.getConnection(servidor, user, pass);
        } catch (Exception e) {
            this.schema = "Streamz";
            this.user = "root";
            this.pass = "";
            this.servidor = "jdbc:mysql://localhost/"+this.schema;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conexion = DriverManager.getConnection(servidor, user, pass);
            } catch (ClassNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }//com.mysql.jdbc.Driver
 catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            e.printStackTrace();
        }
    }

    public Connection getConexion() {
        return conexion;
    }
2

There are 2 answers

0
Tobi On

You can add the port directly after the host:

   private static String servidor = "jdbc:mysql://"+host+":3306/" + schema;
0
Elliott Frisch On

You could specify the port in your URL. Also, I'd use String.format(String, Object...) to build the servidor like

private static String host = "67.222.1.89";
private static int port = 3306;
protected static String schema = "federicoanelli_S"; 
private static String servidor = String.format("jdbc:mysql://%s:%d/%s",
    host,port,schema);