views:

340

answers:

3

Hi, I am new to Java ... is there a similar method to the ReadKey() in C# to avoid that a console application closes?

thanks

A: 

you can use scanner to take some input from the console as following example:

       Scanner sc = new Scanner(System.in);
       String answer;
        ...
       System.out.print("Press Enter to continue...");
       answer = sc.next();
GK
using your method, scanner is not being recognized
mouthpiec
which version of java you are using?
GK
A: 

You will need a while loop to control that.

do{
   String str = //String read from keyboard
   //Your database query here

}
while(str != "BYE" );
Enrique
and what is the command to read from keyboard?
mouthpiec
+1  A: 

One way to do it:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();

there are definitely shorter ones, but I think this one's convenient, because it can easily be extended.

Chris Lercher