Results 1 to 4 of 4
- 10-08-2010, 10:43 PM #1
Senior Member
- Join Date
- May 2010
- Posts
- 113
- Rep Power
- 0
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 10:55 PM.
-
This won't work:
becauseJava Code:connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
isn't a valid StringJava Code:DATABASE_URL,'"+userid +"','"+password+"'
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-08-2010 at 11:10 PM.
- 10-12-2010, 03:40 PM #3
Senior Member
- Join Date
- May 2010
- Posts
- 113
- Rep Power
- 0
- 10-12-2010, 04:21 PM #4
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
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
How to change my form design from "metal" to "nimbus" in Netbeans 6.7.1?
By mlibot in forum New To JavaReplies: 1Last Post: 01-21-2010, 09:20 AM -
how to override "cancel operation" in "progress bar"
By singswt in forum SWT / JFaceReplies: 2Last Post: 10-08-2009, 11:28 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks