Results 1 to 3 of 3
  1. #1
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    114
    Rep Power
    0

    Default calling a create statement method but unable to figure out how in my scenario

    Right now, I have something like the following in my try block:


    Java Code:
        try
          {
            connRemote = DriverManager.getConnection("jdbc:mysql://xx.xx.x.xxx:3306/test",MainUser,MainPass);
                    
            String maindbsql = null;
            maindbsql = "SELECT IP_vch FROM Mytableinxx_xx_x-xxx WHERE IPStatus = 1 "; // Let's says the result fo the query is aa.aa.a.aaa,bb.bb.b.bbb out of 10 IP Addresses present over there.
            
            Map<String,Connection> connections = new HashMap<>();
            DeviceStmt = connRemote.createStatement();
            DeviceRS = DeviceStmt.executeQuery(maindbsql);
    		
            while(DeviceRS.next()){
                
                final String ip_address = DeviceRS.getString("IP_vch");
                System.out.println("Value of IP_vch Field:"+ip_address);
                
                connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass));
            
                if(connections.isEmpty()){
                System.err.println("Status not set to 1 for any of the databases");
                }
            
            }//END Of while(DeviceRS.next())
    		
    		String QueryString = "SELECT query goes here";
    		SelectResultsStmt = (Don't know what to put here?).createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            SelectResultsRS = SelectResultsStmt.executeQuery(QueryString);
    		
    	  }//ENd Of Try block
    
          catch(SQLException ex){
                ex.printStackTrace();
          }

    So, for each of the IPAddresses that I got above in the `maindbsql`, that is `aa.aa.a.aaa` and `bb.bb.b.bbb` I want to call the `createStatement()` method in the following line mentioned in the above code:

    Java Code:
     SelectResultsStmt = (Don't know what to put here?).createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    Since, while establishing connection to these two IPAddresses, I am using `connections.put()` method as follows in the above code:

    Java Code:
    connections.put(ip_address,DriverManager.getConnection("jdbc:mysql://" + ip_address + ":3306/test",RemoteUser,RemotePass));
    I don't have anything like Connection object `connRemote` that I have used for `xx.xx.x.xxx`, for my IP addresses aa.aa.a.aaa and bb.bb.b.bbb .

    Could anyone please let me know if there is any way to overcome this problem?

    Please let me know if I can answer any questions from my end.






    P.S: The IP addresses I have used in my real code are IPV4 addresses and not alphabets.
    Last edited by Jack_Tauson_Sr; 03-29-2014 at 11:29 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: calling a create statement method but unable to figure out how in my scenario

    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: calling a create statement method but unable to figure out how in my scenario

    Java Map Tutorial.

    Though I will ask (as I did in the other thread here) whether you really need a Map, especially if you are not going to access the Values using the IP address Key.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 4
    Last Post: 12-08-2012, 06:03 PM
  2. Replies: 7
    Last Post: 02-14-2012, 10:12 AM
  3. Replies: 6
    Last Post: 03-31-2011, 03:33 PM
  4. Replies: 2
    Last Post: 09-27-2010, 10:04 PM
  5. Unable to figure out this problem! jndi lookup exception.....
    By vrk in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 01-19-2009, 11:38 AM

Posting Permissions

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