using virtual machine like mySql server
        Posted  
        
            by 
                ffmm
            
        on Super User
        
        See other posts from Super User
        
            or by ffmm
        
        
        
        Published on 2012-12-10T16:02:14Z
        Indexed on 
            2012/12/10
            17:07 UTC
        
        
        Read the original article
        Hit count: 227
        
i'm developing a java program and i need a database. Now i'm using MAMP and it's pretty easy but i would have a virtual machine (ubuntu server) and i need to connect my java program with this virtual machine using vitualBox.
the situation:
I installed VirtualBox on my mac and I installed an ubuntu-server machine set "bridge adapter" in the network settings of VB I installed mysql on ubuntu-server and i created a simple database (all work well by ubuntu) doing ifconfig by ubuntu I get the ip: 192.168.1.217 so in the java program i made this function:
public static Connection connect(String host, int port, String dbName, String user,     String passwd)
{
Connection dbConnection = null;
try
{
    String dbString = null;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    dbString = "jdbc:mysql://" + host + ":" + port + "/" + dbName;
    dbConnection = DriverManager.getConnection(dbString, user, passwd);
}
catch (Exception e)
{
    System.err.println("Failed to connect with the DB");
    e.printStackTrace();
}
return dbConnection;
}
and in the main() i use:
Connection con = connect(1, "192.168.1.217", 3306, "Ciao", "root", "cocacola");
3306 was a default value. I don't know if is correct, it works on mamp, but…. how I can find the correct port that I have to use with VB?
when I ran the program I get the catch excepion… what's wrong?
ps: i have to install apache o something else?
© Super User or respective owner