Found 4336 Articles for Java 8

How to convert a timestamp object in to Date in JDBC program?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

454 Views

The getTime() method of the Timestamp class retrieves and returns the time from the current timestamp in milliseconds (long) from epoch time 1, 1970 00:00:00.000 GMT.Timestamp timestamp = rs.getTimestamp("DispatTimestamp"); long time = timestamp.getTime();The constructor of the java.sql.Date class accepts a long variable representing the time in milliseconds from the epoch time and constructs the date object.//Printing the date of dispatch System.out.println("Date of dispatch: "+new Date(time));Using these, you can convert a TimeStamp object to Date object in JDBC.Assume we have established connection with MySQL database and created a table named dispatch_data using statement object as://Creating a Statement object Statement stmt = ... Read More

How to get the row count in JDBC?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

5K+ Views

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Suppose we have established a connection with MySQL and created a table in the database named mydatabase using Statement object as://Creating the Statement object Statement stmt = con.createStatement(); //Query to create a table String query = "CREATE TABLE Cricketers_Data( "    + "First_Name VARCHAR(255), "    + "Last_Name VARCHAR(255), "    + "Date_Of_Birth Date, "    + "Place_Of_Birth VARCHAR(255), "    + "Country VARCHAR(255))"; //Executing the query stmt.execute(query); System.out.println("Table created......");In to this table we ... Read More

How to connect to Derby database using a JDBC program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

Apache Derby is a Relational Database Management System which is fully based on (written/implemented in) Java programming language. It is an open source database developed by Apache Software Foundation.Installing derby:Follow the steps given below to install derby:Visit the home page of Apache Derby home page https://db.apache.org/derby/. Click the Download tab.Select and click on the link of the latest version of Apache Derby.On clicking the selected link, you will be redirected to the Distributions page of apache derby. If you observe here, derby provides distributions namely, db-derby-bin, db-derbylib.zip, db-derby-lib-debug.zip, and db-derby-src.zip.Download the db-derby-bin folder. Copy its contents to a separate folder ... Read More

How to connect to an SQLite database using a JDBC program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

1K+ Views

A. SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. It is a database, which is zero-configured, which means like other databases you do not need to configure it in your system.SQLite engine is not a standalone process like other databases, you can link it statically or dynamically as per your requirement with your application. SQLite accesses its storage files directly.The URL to connect with SQLite database is jdbc:sqlite:test.db and, the driver class name to connect to it is org.sqlite.JDBC.Before you proceed with the example:Download latest version of sqlite-jdbc-(VERSION).jar from sqlite-jdbcrepository.Add downloaded jar file ... Read More

How to call an existing function in a database using JDBC API?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

6K+ Views

You can call a function using CallableStatement object just like stored procedures, to call a function using a JDBC program you need to.Connect to the database.Create a PreparedStatement object and to its constructor pass the function call in String format.Set values to the place holders.Execute the Callable statement.Following is the query to call a function from JDBC:{? = call getDob(?)}As you observe the query contains place holders (?) just like prepared and callable statements.In the above query, the first place holder represents the return value of the function and the second placeholder represents the input parameter.You need to register the ... Read More

How to create a function in a database using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

966 Views

Like procedures, you can also create function in a database and store them.SyntaxFollowing is the syntax of creating a function in a(MySQL) database:CREATE FUNCTION Function_Name(input_arguments) RETURNS output_parameter BEGIN declare variables; statements . . . . . . . . . . return data_type; ENDTo create a function in a database using JDBC API you need to:Register the driver: class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing ... Read More

How to call a stored procedure that returns output parameters, using JDBC program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

9K+ Views

A. Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.You can call a stored procedure using the following syntax:CALL procedure_name (input_parameter1, input_parameter2, input_parameter3)JDBC provides a standard stored procedure SQL escape syntax using which you can procedures in all RDBMSsTo call a stored procedure using a JDBC program you need to:Register the driver: ... Read More

How to call a stored procedure that accepts input parameters, using JDBC program?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

3K+ Views

A. Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.You can call a stored procedure using the following syntax:CALL procedure_name (input_parameter1, input_parameter2, input_parameter3)JDBC provides a standard stored procedure SQL escape syntax using which you can procedures in all RDBMSsTo call a stored procedure using a JDBC program you need to:Register the driver: ... Read More

How to call an existing stored procedure in a database using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

699 Views

A. Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.You can call a stored procedure using the following syntax:CALL procedure_name ()JDBC provides a standard stored procedure SQL escape syntax using which you can procedures in all RDBMSsTo call a stored procedure using a JDBC program you need to:Register the driver: Register the ... Read More

How to create a Stored procedure in a database using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

2K+ Views

A. Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.To create a stored procedure in (MySQL) a database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database ... Read More

Advertisements