Results 1 to 9 of 9
  1. #1
    lasharazmadze is offline Member
    Join Date
    May 2013
    Location
    Rustavi, Georgia
    Posts
    4
    Rep Power
    0

    Question JDBC Connection over network

    Hello guys.

    I have Java application using swing, I want to connect my oracle thin database over network but it fails.

    I've added 1521 port to my firewall inbound rules, and also forwarded 1521 from my router, but it fails.

    can anyone help me? thanks a lot.

    Java Code:
    package connection;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    
    public class DBConnection {
    	private static Connection connection = null;
    
    	public static Connection getConnection() {
    		if (connection != null)
    			return connection;
    		else {
    			try {
    				Class.forName("oracle.jdbc.driver.OracleDriver");
    				connection = DriverManager.getConnection(
    						"jdbc:oracle:thin:@myipaddress:1521:XE", "User",
    						"password");
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    
    			return connection;
    		}
    	}
    
    }

  2. #2
    Join Date
    Apr 2014
    Location
    http://www.roytuts.com
    Posts
    51
    Rep Power
    0

    Default Re: JDBC Connection over network

    what exception do you get ?

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: JDBC Connection over network

    You mentioned that you added the rule to forward the port to your router. You are trying to connect to the outer ip that your router got from your provider? Maybe you tell us the first numbers of the ip address that you try to connect to.

    And I test connections with the sql developer first to see that the network is setup correctly. That wau it cannot be an issue with my code...

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,367
    Rep Power
    6

    Default Re: JDBC Connection over network

    Quote Originally Posted by kneitzel View Post
    And I test connections with the sql developer first to see that the network is setup correctly. That wau it cannot be an issue with my code...
    99/100 times JDBC connectivity issues aren't code related anyway, since the code is so brain-numbingly simple and standardized. We'll just wait and see what the actual error is.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    lasharazmadze is offline Member
    Join Date
    May 2013
    Location
    Rustavi, Georgia
    Posts
    4
    Rep Power
    0

    Default Re: JDBC Connection over network

    I do not get any exception. In eclipse on my host computer it works without any problem. but when I build a .jar file and send to another computer, it does not work, while trying search some info in database, it could not be found.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,367
    Rep Power
    6

    Default Re: JDBC Connection over network

    That is probably because that other computer is not allowed to connect to the database; simple logic. You are also probably running the application in a way that you can't actually see the exceptions that occur.

    If you run the program using java -jar yourjar.jar from the command prompt you can see any exception that the application produces with your current error handling code.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    lasharazmadze is offline Member
    Join Date
    May 2013
    Location
    Rustavi, Georgia
    Posts
    4
    Rep Power
    0

    Default Re: JDBC Connection over network

    Quote Originally Posted by gimbal2 View Post
    That is probably because that other computer is not allowed to connect to the database; simple logic. You are also probably running the application in a way that you can't actually see the exceptions that occur.

    If you run the program using java -jar yourjar.jar from the command prompt you can see any exception that the application produces with your current error handling code.
    no any exception.


    and do I have to install some additional files or how I can allow other computers to access my database? I'm very new in thing like this

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: JDBC Connection over network

    Do all the catch blocks in the code have calls to the printStackTrace() method so any error would be printed?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    lasharazmadze is offline Member
    Join Date
    May 2013
    Location
    Rustavi, Georgia
    Posts
    4
    Rep Power
    0

    Default Re: JDBC Connection over network

    Quote Originally Posted by Norm View Post
    Do all the catch blocks in the code have calls to the printStackTrace() method so any error would be printed?
    I have almost all methods in try catch blocks and printing a stack trace

Similar Threads

  1. Replies: 0
    Last Post: 07-27-2012, 08:10 PM
  2. Getting string from network connection (Reader)
    By Genom in forum New To Java
    Replies: 12
    Last Post: 02-17-2011, 01:29 AM
  3. JDBC Connection...
    By onlysumitg in forum JDBC
    Replies: 3
    Last Post: 08-21-2009, 12:34 PM
  4. Replies: 0
    Last Post: 05-31-2009, 08:11 AM
  5. Using Applets for network connection
    By bugger in forum New To Java
    Replies: 0
    Last Post: 11-19-2007, 06:16 PM

Posting Permissions

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