Results 1 to 4 of 4
  1. #1
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Question connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');

    Hi


    I want the user id and password to be users input values .

    How can i do that in this line.
    It is pointing to an error if i write the variables userid and password .


    Java Code:
       public static void main(String[] args) throws ClassNotFoundException {
    :
    :
    //          Calling the procedure to enter the correct user_id
    			String userid = f_userid(scan);	
    //          Calling the procedure to enter the correct password
    			String password = f_password(scan);
    connection = DriverManager.getConnection(DATABASE_URL,userid,password);  ----> how can i use the userid and password given by user at the console be used here ....
                                                                                                                       // every different user has his own userid and password
    }//end of main
    private static String f_userid(Scanner scan) {
    		System.out.println("Enter user id : ");
    		String user_id = scan.next();  //Scan the input 
    		int userlen = user_id.length();
    		while(userlen != 5){	
    			System.out.println("The user id is less than 5 characters long .PLEASE ENTER RIGHT USERID ");
    			System.out.println("Please enter userid again of 5 characters length : ");
    			user_id = scan.next();  //Scan the input 
    			userlen = user_id.length();
    			System.out.println("The given user id is :"+user_id);
    		}
    		return user_id;
    	}
    Last edited by renu; 10-08-2010 at 11:55 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    This won't work:
    Java Code:
    connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
    because
    Java Code:
    DATABASE_URL,'"+userid +"','"+password+"'
    isn't a valid String

    So as the parameter for this method must be a String (if that's the overload that you're using), you'll need to provide it with a valid String.

    One solution is to use one of the other overloads for this method. The API will show you how.
    Last edited by Fubarable; 10-09-2010 at 12:10 AM.

  3. #3
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    This won't work:
    Java Code:
    connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
    because
    Java Code:
    DATABASE_URL,'"+userid +"','"+password+"'
    isn't a valid String

    So as the parameter for this method must be a String (if that's the overload that you're using), you'll need to provide it with a valid String.

    One solution is to use one of the other overloads for this method. The API will show you how.
    Can you pls help me , on how to pass the username and password to the connection object .

    Thanks in advance

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Use the below method properly
    static Connection getConnection(String url, String user, String password)
    Attempts to establish a connection to the given database URL.


    for the above method u have to pass 3 parameters. example u should use like this
    String databaseurl = "some url"
    String userid = "test",
    String password = "test"

    So u have to use the above string like this below for the api method
    DriverManager.getConnection(databaseurl,userid,pas sword)
    Ramya:cool:

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 04:03 AM
  2. Replies: 1
    Last Post: 01-21-2010, 10:20 AM
  3. Replies: 2
    Last Post: 10-09-2009, 12:28 AM
  4. Replies: 2
    Last Post: 01-24-2009, 07:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 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
  •