Audio Alief
Audio Alief

Reputation: 47

How to split a string with comma separated values from table into 2 text fields?

I have a table as seen below:

tabel

I have one JTextField which is the left one, and JDateChooser which is the right next to the text field.

enter image description here

How to retrieve the TTL column value and set them into 2 text fields which the first value before comma should be in first text field, and the second value after comma should be in date chooser?

Upvotes: 3

Views: 1418

Answers (1)

Yousaf
Yousaf

Reputation: 29292

Check this page in order to do the query to your DB. Your query should be something like the following example:

SELECT * 
FROM YOUR_DB_NAME
WHERE NIK=?

If you prefer to reduce the volume of data returned from the DB you may choose select only the TTL column. After this, split the value of TTL column using split method

String str = "bulan,10-11-2017";
String[] parts = str.split(",");

Split method will return an array containing different parts of the original String that were split based on the delimiter that was passed into split() method.

Example

For example you queried the database and the resultset contains the data returned from the database.

You then need to get the value of the TTL column from the resultset and save it some String type variable

String str = rs.getString("TTL");

Now use split method on this str variable

 str = "bulan,10-11-2017";
 String[] parts = str.split(",");

For help with how to query the database, see the link provided above

Upvotes: 2

Related Questions