Found 317 Articles for JDBC

Java DatabaseMetaData getDriverMajorVersion() method with example

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

145 Views

The getDriverMajorVersion() method of the DatabaseMetaData interface returns the major version of the JDBC driver used.To get the major version of the JDBC driver used to connect with the database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData object with respect to the current connection using the ... Read More

How to reorder the columns of a table in JDBC?

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

184 Views

You can reorder the columns of a table in MySQL database using the ALTER TABLE command.SyntaxALTER TABLE table_name MODIFY column_name datatype AFTER another_columnAssume we have a table named dispatches_data in the database with 7 columns namely ProductName, CustomerName, DispatchDate, DeliveryTime, Price, Location and, ID with description as −//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),    Price INT,    Location VARCHAR(255),    DispatchTimeStamp timestamp);Now, we will ... Read More

Java sql.Time valueOf() method with example

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

1K+ Views

The valueOf() method of the java.sql.Time class accepts a String value representing a time in JDBC escape format and converts the given String value into Time object.Time time = Time.valueOf("time_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.Time toString() method with example

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

680 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

463 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

649 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

903 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

Java sql.Timestamp toString() method with example

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

5K+ Views

The toString() method of the java.sql.Timestamp class returns the JDBC escape format of the time stamp of the current Timestamp object as String variable.i.e. using this method you can convert a Timestamp object to a String.//Retrieving the Time object Timestamp timestampObj = rs.getTimestamp("DispatchTimeStamp"); //Converting the Time object to String format String time_stamp = timestampObj.toString();ExampleLet us create a table with the 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 ... Read More

Advertisements