Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the content of text area is empty (java)

Tags:

java

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
}
like image 917
user1748910 Avatar asked Nov 17 '25 14:11

user1748910


1 Answers

String data=todo_area.getText().trim(); //read contents of text area into 'data'
  if(!data.equals("")) {
     // code
    }
like image 164
Rasel Avatar answered Nov 19 '25 07:11

Rasel