Found 4336 Articles for Java 8

Write an example JDBC program demonstrating the batch processing with statement object?

Nancy Den
Updated on 30-Jul-2019 22:30:25

116 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing. The Statement interface provides methods to perform batch processing such as addBatch(), executeBatch(), clearBatch().Follow the steps given below to perform batch updates using the Statement object:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create a Statement object using the createStatement() method of the Connection interface.Set the auto-commit to ... Read More

What is batch processing in JDBC?

Nancy Den
Updated on 30-Jul-2019 22:30:25

219 Views

Grouping related SQL statements into a batch and executing/submitting them at once is known as batch processing.While executing a set of statements one after other the execution switches from the database to program simultaneously.Using batch processing we can reduce this communication overhead and increase the performance of our Java application.For Example, if we have a table named Emp with the following description:+----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | Name | varchar(255) | YES | ... Read More

How to execute DELETE SQL in a JSP?

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

702 Views

The tag executes an SQL statement that does not return data; for example, SQL INSERT, UPDATE, or DELETE statements.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultsqlSQL command to execute (should not return a ResultSet)NoBodydataSourceDatabase connection to use (overrides the default)NoDefault databasevarName of the variable to store the count of affected rowsNoNonescopeScope of the variable to store the count of affected rowsNoPageExampleTo start with basic concept, let us create a simple table Employees table in the TEST database and create few records in that table as follows −Step 1Open a Command Prompt and change to the installation directory as follows ... Read More

How to execute UPDATE SQL in a JSP?

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

1K+ Views

The tag executes an SQL statement that does not return data; for example, SQL INSERT, UPDATE, or DELETE statements.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultsqlSQL command to execute (should not return a ResultSet)NoBodydataSourceDatabase connection to use (overrides the default)NoDefault databasevarName of the variable to store the count of affected rowsNoNonescopeScope of the variable to store the count of affected rowsNoPageExampleTo start with basic concept, let us create a simple table Employees table in the TEST database and create few records in that table as follows −Step 1Open a Command Prompt and change to the installation directory as follows ... Read More

How to execute SQL update query in a JSP?

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

398 Views

The tag executes an SQL statement that does not return data; for example, SQL INSERT, UPDATE, or DELETE statements.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultsqlSQL command to execute (should not return a ResultSet)NoBodydataSourceDatabase connection to use (overrides the default)NoDefault databasevarName of the variable to store the count of affected rowsNoNonescopeScope of the variable to store the count of affected rowsNoPageExampleTo start with basic concept, let us create a simple table Employees table in the TEST database and create few records in that table as follows −Step 1Open a Command Prompt and change to the installation directory as follows ... Read More

How to executes an SQL SELECT statement in a JSP?

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

3K+ Views

The tag executes an SQL SELECT statement and saves the result in a scoped variable.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultsqlSQL command to execute (should return a ResultSet)NoBodydataSourceDatabase connection to use (overrides the default)NoDefault databasemaxRowsMaximum number of results to store in the variableNoUnlimitedstartRowNumber of the row in the result at which to start recordingNo0varName of the variable to represent the databaseNoSet defaultscopeScope of variable to expose the result from the databaseNoPageExampleTo start with the basic concept, let us create an Employees table in the TEST database and create few records in that table as follows −Follow these steps ... Read More

How to insert current date and time in a database using JDBC?

Nancy Den
Updated on 30-Jul-2019 22:30:25

5K+ Views

The time stamp dataType in MySQL database stores day, month, year, hour, minute, second, fractional seconds. Using this you can represent date and time at once.There are two ways to insert/get current time stamp values while working with JDBC.Using the database default value for a date.Using the getTime() method of the calendar class.Database default valueCreate a table named sample to store time stamps in MySQL database using the following query:CREATE TABLE Sample(Id INT, Current_Time_Stamp TimeStamp);Now describe the table as shown below:+--------------------+-----------+------+-----+-------------------+ | Field              | Type      | Null | Key | Default   ... Read More

How to set the data source in a JSP?

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

433 Views

The tag sets the data source configuration variable or saves the data-source information in a scoped variable that can be used as input to the other JSTL database actions.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultdriverName of the JDBC driver class to be registeredNoNoneurlJDBC URL for the database connectionNoNoneuserDatabase usernameNoNonepasswordDatabase passwordNoNonepasswordDatabase passwordNoNonedataSourceDatabase prepared in advanceNoNonevarName of the variable to represent the databaseNoSet defaultscopeScope of the variable to represent the databaseNoPageExampleConsider the following information about your MySQL database setup −We are using JDBC MySQL driver.We are going to connect to TEST database on local machine.We would use user_id and my ... Read More

How to insert Timestamp value in a database using JDBC program?

Nancy Den
Updated on 30-Jul-2019 22:30:25

3K+ Views

Timestamp datatype in SQL is similar to Date (in SQL) both store day:month:year:hour:minute:second. In addition to this timestamp stores fractional seconds too.Inserting Timestamp in to a databaseThe PreparedStatement interface provides a method named setTimestamp() this method accepts two parameters an integer variable representing the parameter index of the place holder at which you need to store the timestamp and a long variable representing the number of milliseconds from the epoch time(standard base time I.e. January 1, 1970, 00:00:00 GMT) to the required time.ExampleAssume we have a table in the database named dispatches with the following description −+------------------+--------------+------+-----+-------------------+ | Field   ... Read More

Which library can be used to interact with database in JSP?

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

160 Views

The JSTL SQL tag library provides tags for interacting with relational databases (RDBMSs) such as Oracle, MySQL, or Microsoft SQL Server.Following is the syntax to include JSTL SQL library in your JSP −Following table lists out the SQL JSTL Tags −S.No.Tag & Description1Creates a simple DataSource suitable only for prototyping2Executes the SQL query defined in its body or through the sql attribute.3Executes the SQL update defined in its body or through the sql attribute.4Sets a parameter in an SQL statement to the specified value.5Sets a parameter in an SQL statement to the specified java.util.Date value.6Provides nested database action elements with ... Read More

Advertisements