Issue
I am currently doing a school project in java (I use NetBeans) and I come across this problem. I have done some online research but no luck so far. Here is a snippet of my code: the problem is that whenever I click run file, the console only displays the message in the help() method but not this message "Command [c/r/u/d/x]". the message is only shown after input any of the possible options. Any help would be appreciated.
public static void main(String[] args) throws ClassNotFoundException, SQLException {
new TestDB().menu();
}
private DBConnector connector;
private Connection conn;
private DBManager manager;
public TestDB() throws ClassNotFoundException, SQLException {
connector = new DBConnector(); conn = connector.openConnection();
manager = new DBManager(conn);
}
private void testCreate() throws SQLException {
System.out.println("Adding customer to the database: ");
manager.addCustomer(read("Email"),read("Password"),read("First
Name"),read("Last Name"),read("Phone
Num"),read("Address"),read("DOB"));
System.out.println("Customer added successfully ");
}
private String read(String prompt) {
System.out.print(prompt + ": ");
System.out.flush();
return in.nextLine();
}
private String read(int prompt) {
System.out.print(prompt + ": ");
System.out.flush();
return in.nextLine();
}
private void menu() throws SQLException {
char c;
help();
while ((c = read("Command [c/r/u/d/f/x]").charAt(0)) != 'x') {
switch (c) {
case 'c':
testCreate();
break;
case 'r':
testFind();
break;
case 'u':
testUpdate();
break;
case 'd':
testDelete();
break;
default:
help();
break;
}
}
}
private void help() {
System.out.println("Database Operations: \n"
+ "c = Create User \n"
+ "r = Find User \n"
+ "u = Update User \n"
+ "d = Delete User \n");
}
Solution
Issue resolved, I just replace print() to println() in my read() method. The problem seems to belong to some different between maven and ant project. I try the same code in ant and it execute perfectly.
New update: this site help me: https://github.com/mojohaus/exec-maven-plugin/issues/159. Basically, you just need to change the goal from exec:exec to exec:java
Answered By - Quientus