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
}
String data=todo_area.getText().trim(); //read contents of text area into 'data'
if(!data.equals("")) {
// code
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With