11

I am working on a CLI Spring shell code in IntelliJ. I run it and give some parameters. But when I type insert and press enter, console doesn't take it and it appears as if nothing happened!

My code:

@Component
public class HelloWorldCommands implements CommandMarker {

    @CliCommand(value = "insert", help = "insert data to ParsEMS DB")
    public void insert() {
        try {
            Class.forName("org.postgresql.Driver");
            Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ParsEMS", "xxxxxx", "xxxxxxx");
            Statement st = con.createStatement();
            st.executeUpdate("INSERT INTO node (name, destination) VALUES ('b', 200)");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("insert to ParsEMS DB");
    }
}



public class Main {
    public static void main(String[] args) throws Exception {
        Bootstrap.main(args);
    }
}   

I see below result when I run it;

1.1.0.RELEASE

Welcome to Spring Shell. For assistance press or type "hint" then hit ENTER.

spring-shell>

jh314
  • 27,144
  • 16
  • 62
  • 82
Sajad NasiriNezhad
  • 699
  • 1
  • 7
  • 27
  • 1
    I'm giving you the benefit of the doubt with this edit, and am adding in the missing curly braces that were omitted with your code. I would encourage you to be explicit about what you're seeing and what you're not seeing. Do you see any data values added to the database? Do you see any messages printed out in the console? What happens when you attach the debugger to this code and run it? – Makoto May 26 '15 at 05:59
  • ***thanks a lot***. **1: Do you see any data values added to the database?** *no nothing happen*. **2: Do you see any messages printed out in the console?** *no message printed out*. **3: What happens when you attach the debugger to this code and run it?** *sorry sir. i don't understand what you mean! because i'm a beginner in java* . – Sajad NasiriNezhad May 26 '15 at 07:19

1 Answers1

22

Spring Shell uses Jline. You will have to edit the run configuration inside your Intellij and add the vm options arguments as follow:

Unix machines:

-Djline.terminal=org.springframework.shell.core.IdeTerminal

On Windows machines:

-Djline.WindowsTerminal.directConsole=false -Djline.terminal=jline.UnsupportedTerminal
4F2E4A2E
  • 1,964
  • 26
  • 28