Check if the content of text area is empty (java)
java
Solution
String data=todo_area.getText().trim(); //read contents of text area into 'data'
if(!data.equals("")) {
// code
}
Problem
I am trying to read data from a `textarea (JTextArea)` and store the contents into a `table(MySQL)`. I don't want the `INSERT` query to execute if the textarea is empty or has a newline without any text. I tried the following code but it does not work. Could someone help me out. Thanks. ``` String data=todo_area.getText();//read contents of text area into 'data' String newline = System.getProperty("line.separator"); boolean hasNewline = data.contains(newline); if (data == null || !data.trim().equals("")||hasNewline==false) { //INSERT query } ```