Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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:


        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:

     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:

    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.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

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

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Yes. Could you answer?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

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

    No, I was just pointing it out for others.
    See: http://www.javaprogrammingforums.com...s-posting.html
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Okay, that would be helpful for others if they read replies from other forums as well but no one has answered as of yet.

Similar Threads

  1. Random Boolean in an if statement (tricky, can't seem to figure out)
    By Xhalite in forum Loops & Control Statements
    Replies: 6
    Last Post: May 29th, 2013, 07:28 AM
  2. HELP: UNABLE TO CREATE AND PRINT A 3-DIMENSIONAL ARRAY
    By baraka.programmer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 3rd, 2011, 03:44 PM
  3. New to Java Can not figure out how to create a table with my codes outputs!
    By shoppa028 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 12th, 2011, 09:21 AM
  4. unable to execute prepared statement
    By nrao in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 11th, 2010, 08:26 PM
  5. Unable to create a new connection!
    By fh84 in forum JDBC & Databases
    Replies: 1
    Last Post: November 20th, 2009, 05:58 PM