
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 317 Articles for JDBC

245 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

277 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

2K+ Views
In this program, we'll demonstrate how to insert and retrieve records from a MySQL database using JDBC . Specifically, we'll focus on how to convert a time value from a String format into a java.sql.Time object using the valueOf() method. This allows us to store time values in a database and retrieve them accurately. Time time = Time.valueOf("time_string"); Steps to Use sql.Time valueOf() Method Following are the steps to use sql.Time valueOf() method − Import all the useful classes. Register the Driver by loading the MySQL JDBC driver. ... Read More

980 Views
In this article, you'll learn how to convert a Time object into a String using the toString() method from the java.sql.Time class. This method allows us to easily transform a Time object into its JDBC escape format, which can then be handled as a string. //Retrieving the Time object Time timeObj = rs.getTime("DeliveryTime"); //Converting the Time object to String format String time = timeObj.toString(); Steps for using Java sql.Time toString() Method Following are the steps for using Java sql.Time toString() Method − Create a MySQL table named dispatches. Insert some sample records into ... Read More

646 Views
In this article, we will learn the usage of the setTime() method in Java with a complete example. Handling time-related data is an essential aspect of many Java applications, especially when interacting with databases. The java.sql.Time class, designed to handle SQL TIME values. What is setTime() method 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); Use Cases of setTime() Following are the use ... Read More

4K+ 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

6K+ 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

930 Views
In this program, we will connect to a MySQL database using JDBC, insert a new record into the dispatches table, and retrieve all records from the table. The setTime() method from Date class of java.util package that 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); The goal of the program is to demonstrate how to interact with a database using JDBC and handle Date and Time objects in Java. ... Read More

1K+ 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

7K+ 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