Found 4336 Articles for Java 8

Java sql.Time toString() method with example

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

681 Views

The toString() method of the java.sql.Time class returns the JDBC escape format of the time of the current Time object as String variable.i.e. using this method you can convert a Time object to a String.//Retrieving the Time object Time timeObj = rs.getTime("DeliveryTime"); //Converting the Time object to String format String time = timeObj.toString();ExampleLet us create a table with name dispatches in MySQL database using CREATE statement as follows −CREATE TABLE dispatches(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches table using INSERT statements ... Read More

Java sql.Time setTime() method with example

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

464 Views

The setTime() method of the java.util.Time class accepts a variable of long type, representing the number of milliseconds from the epoch time (January 1, 1970 00:00:00.000 GMT) to the required time, and sets the specified time value to the current Time object//Setting time time.setTime(time_value_in_long);ExampleLet us create a table with name dispatches in MySQL database using CREATE statement as follows −CREATE TABLE dispatches(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches table using INSERT statements −insert into dispatches values('Key-Board', 'Raja', DATE('2019-09-01'), TIME('11:00:00'), 7000, 'Hyderabad'); ... Read More

Java sql.Date valueOf() method with example

Arushi
Updated on 30-Jul-2019 22:30:26

3K+ Views

The valueOf() method of the java.sql.Date class accepts a String value representing a date in JDBC escape format (yyyy-mm-dd) and convertsthe given String value into Date object.Date date = Date.valueOf("date_string");ExampleLet us create a table with name dispatches in MySQL database using CREATE statement as follows −CREATE TABLE dispatches(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches table using INSERT statements −insert into dispatches values('Key-Board', 'Raja', DATE('2019-09-01'), TIME('11:00:00'), 7000, 'Hyderabad'); insert into dispatches values('Earphones', 'Roja', DATE('2019-05-01'), TIME('11:00:00'), 2000, 'Vishakhapatnam'); insert into dispatches values('Mouse', 'Puja', ... Read More

Java sql.Date toString() method with example?

Rishi Raj
Updated on 30-Jul-2019 22:30:26

4K+ Views

The toString() method of the java.sql.Date class returns the JDBC escape format of the time of the current Date object as String variable.i.e. using this method, you can convert a Date object to a String.//Retrieving the Date object Date dateObj = rs.getDate("DispatchDate"); //Converting the Date object to String format String date = dateObj.toString();ExampleLet us create a table with name dispatches in MySQL database using CREATE statement as follows −CREATE TABLE dispatches(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches table using INSERT statements ... Read More

Java sql.Date setTime() method with example.

Arushi
Updated on 30-Jul-2019 22:30:26

654 Views

The setTime() method of the java.util.Date class accepts a variable of long type, representing the number of milliseconds from the epoch time (January 1, 1970 00:00:00.000 GMT) to the required time, and sets the specified time value to the current Date object.//Setting time date.setTime(time_value_in_long);ExampleLet us create a table with name dispatches in MySQL database using CREATE statement as follows −CREATE TABLE dispatches(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches table using INSERT statements −insert into dispatches values('Key-Board', 'Raja', DATE('2019-09-01'), TIME('11:00:00'), 7000, 'Hyderabad'); ... Read More

Java sql.Timestamp valueOf() method with example

Rishi Raj
Updated on 30-Jul-2019 22:30:26

911 Views

The valueOf() method of the java.sql.Timestamp class accepts a String value representing a time stamp in JDBC escape format and converts the given String value into Timestamp object.Timestamp timeStamp = Time.valueOf("timeStamp_string");ExampleLet us create a table with name dispatches_data in MySQL database using CREATE statement as shown below:CREATE TABLE dispatches_data(    ProductName VARCHAR(255),    CustomerName VARCHAR(255),    DispatchTimeStamp timestamp,    Price INT,    Location VARCHAR(255));Now, we will insert 5 records in dispatches_data table using INSERT statements:insert into dispatches_data values('Key-Board', 'Raja', TIMESTAMP('2019-05-04', '15:02:45'), 7000, 'Hyderabad'); insert into dispatches_data values('Earphones', 'Roja', TIMESTAMP('2019-06-26', '14:13:12'), 2000, 'Vishakhapatnam'); insert into dispatches_data values('Mouse', 'Puja', TIMESTAMP('2019-12-07', '07:50:37'), 3000, 'Vijayawada'); insert into ... Read More

How to close JFrame on the click of a Button in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

11K+ Views

Set frame.dispose() on the click of a button to close JFrame. At first create a button and frame −JFrame frame = new JFrame(); JButton button = new JButton("Click to Close!");Now, close the JFrame on the click of the above button with Action Listener −button.addActionListener(e -> {    frame.dispose(); });The following is an example to close JFrame on the click of a Button −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Click to Close!");   ... Read More

Java Program to display Frame after some seconds

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

281 Views

Use Timer() to set seconds for delay i.e. to display frame after a few seconds −Timer tm = new Timer(2000, new ActionListener() {    // }The following is an example to display Frame after some seconds −package my; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.Timer; public class SwingDemo extends JFrame {    private JFrame frame = new JFrame();    public SwingDemo() {       frame.setSize(550, 300);       frame.setDefaultCloseOperation(EXIT_ON_CLOSE);       frame.setVisible(true);       frame.setExtendedState(JFrame.ICONIFIED);       Timer tm = new Timer(2000, new ActionListener() {          @Override         ... Read More

How to change JFrame background color in Java

Samual Sam
Updated on 30-Jul-2019 22:30:26

19K+ Views

At first, create a JFrame −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(550, 300));Now, change the background color of the JFrame −frame.getContentPane().setBackground(Color.BLUE);The following is an example to change JFrame background color −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setPreferredSize(new Dimension(550, 300));       frame.getContentPane().setBackground(Color.BLUE);       frame.pack();       frame.setVisible(true);    } }Output

How can we set Mnemonic Key Radio Button in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

295 Views

Mnemonic key is set so that a user can use Keyboard keys to select a Radio Button. For example, a key can be set with ALT −radio2.setMnemonic(KeyEvent.VK_R);Above, we have set key ALT+R for radio2.The following is an example to set Mnemonic key radio button −package my; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JRadioButton; public class SwingDemo {    public static void main(String[] args) {       JRadioButton radio1 = new JRadioButton("Male");       JRadioButton radio2 = new JRadioButton("Female");       radio2.setMnemonic(KeyEvent.VK_R);       ButtonGroup group = new ButtonGroup();       ... Read More

Advertisements