Search code examples
javatextinsertjtextfieldsymbols

Insert code that contains "" or () into texfield


How can I set textfield with sql code like this:

sqlcodefield.setText("("Select IP from Test where (Ipdate > 01.01.2010)");")

well it sure doesnt work cause there are multiple "" and (). Hope you understand.I dont need to execute any query just insert code in textfield


Solution

  • Double quote characters " are used to indicate the beginning and ending of a string. They need to be escaped within a String to indicate that they are a special character. To set the text for the JTextField, you can use

    sqlcodefield.setText("(\"Select IP from Test where (Ipdate > 01.01.2010)\");");