Results 1 to 3 of 3
  1. #1
    tugalsan is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Cool TWO IPs FOR MY MYSQL CONNECTION

    I made a program that can use jdbc connection. in there I configured mysql. in there i stored a WAN ip and a LAN ip to connect my server.

    my program tries to connect my LAN ip first. if it not works (which takes more than 1 minute), it continues to try to connect with my WAN ip. Hence, on another network to start my program, i have to wait approximately 2 minutes.

    is there any way to overcome this lag that anyone experienced and solved?

    HERE IS MY MAIN:
    public static void main(String[] arg) {
    try {
    TK_DialogUtilsStartProgramConfig spc = TK_DialogUtils.startProgram(arg, PROGRAM_ID, "Tugalsan Karabacak'in SQL Programi", "Tugalsan Karabacak's SQL Application", "autoSQL.jar", false, false, true);
    new TK_SQLGuiConDialog(spc, new TK_SQLGuiConHolder(), spc.isAdmin() ? TK_SQLGuiConDialog.ACTION_GUI_SAVEENABLE : TK_SQLGuiConDialog.ACTION_NONGUI_CONNECTION) {

    @Override
    @SuppressWarnings("ResultOfObjectAllocationIgnored ")
    public void afterConnectOperations(TK_DialogUtilsStartProgramC onfig spc, String dbName, TK_SQLConnection c) {
    new Run(spc, dbName, c);
    }
    };
    } catch (Exception e) {
    TK_DialogUtils.showMessage(null, e);
    }
    }

    HERE IS MY MYSQL CONNECTION:
    } else if (xh.config instanceof TK_SQLGuiConMySql) {
    TK_SQLGuiConMySql o = (TK_SQLGuiConMySql) xh.config;
    u = o.getUserName().trim().equals("") ? null : o.getUserName().trim();
    p = o.isPasswordEnable() ? spc.getAdminPass() : "";
    try {
    System.out.println("Connecting LAN ip...");
    c = new TK_SQLConnectionMySql(o.getServerName(), o.getPortNumber(), o.getDatabaseName(), u, p);
    } catch (Exception e) {
    if (TK_NetworkUtils.isConnectedToInternet()) {
    System.out.println("Connecting WAN ip...");
    c = new TK_SQLConnectionMySql(o.getServerName2(), o.getPortNumber(), o.getDatabaseName(), u, p);
    } else {
    System.out.println("Skipping WAN ip...");
    throw new Exception();
    }
    }
    dbName = o.getDatabaseName();
    Last edited by tugalsan; 03-20-2010 at 05:17 PM.

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Two possibilities (both outside the scope of a Java support forum):

    1. Use a Fully Qualified Domain Name rather than an IP address in your connection settings, and configure DNS to show you the LAN address while you're on the inside network, and the WAN address when you're on the public Internet.

    2. Use the WAN address all the time, and configure NAT properly on your firewall so it works.

    -Gary-

  3. #3
    tugalsan is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    I solved it with my java knowlage only :)
    Thanks for comments anyway...

    } else if (xh.config instanceof TK_SQLGuiConMySql) {
    final TK_SQLGuiConMySql o = (TK_SQLGuiConMySql) xh.config;
    u = o.getUserName().trim().equals("") ? null : o.getUserName().trim();
    p = o.isPasswordEnable() ? spc.getAdminPass() : "";
    new Thread(new Runnable() {

    @Override
    public void run() {
    try {
    con1 = new TK_SQLConnectionMySql(o.getServerName(), o.getPortNumber(), o.getDatabaseName(), u, p);
    } catch (Exception ex) {
    }
    con1Fin = true;
    }
    }).start();
    new Thread(new Runnable() {

    @Override
    public void run() {
    try {
    con2 = new TK_SQLConnectionMySql(o.getServerName2(), o.getPortNumber(), o.getDatabaseName(), u, p);
    } catch (Exception ex) {
    }
    con2Fin = true;
    }
    }).start();
    TK_Date de = new TK_Date();
    TK_Date dn = new TK_Date();
    de.incrementSecond(60);
    while (de.hasGreaterTimeThan(dn)) {
    if (con1Fin && con1 != null) {
    c = con1;
    break;
    }
    if (con2Fin && con2 != null) {
    c = con2;
    break;
    }
    if (con1Fin && con2Fin) {
    break;
    }
    TK_Runtime.waitFor(1);
    dn.setTimeNow();
    }
    if (c == null) {
    throw new Exception();
    }
    dbName = o.getDatabaseName();

Similar Threads

  1. Java-mysql connection
    By Kligham in forum New To Java
    Replies: 16
    Last Post: 11-25-2009, 01:28 PM
  2. java mysql connection
    By sysout in forum New To Java
    Replies: 5
    Last Post: 10-31-2009, 10:48 AM
  3. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  4. Replies: 1
    Last Post: 10-29-2008, 05:38 PM
  5. no mysql connection
    By scchia in forum New To Java
    Replies: 12
    Last Post: 07-19-2008, 07:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •