Found 9326 Articles for Object Oriented Programming

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

426 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

157 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

How to specify the encoding type used by forms that post data back to the Web application in a JSP?

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

250 Views

The tag is used to specify the encoding type used by forms that post data back to the Web application.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultkeyName of character encoding you want to apply when decoding request parameters.YesNoneYou use the tag when you want to specify the character encoding for decoding data posted from forms. This tag must be used with character encodings that are different from ISO-8859-1. The tag is required since most browsers do not include a Content-Type header in their requests.The purpose of the tag is to specify the content type of the request. ... Read More

How to maps key to the localized message and performs the parametric replacement in a JSP?

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

141 Views

The tag maps key to the localized message and performs the parametric replacement.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultkeyMessage key to retrieveNoBodybundleResource bundle to useNoDefault bundlevarName of the variable to store the localized messageNoPrint to pagescopeThe scope of the variable to store the localized messageNoPageExample JSTL fmt:message Tag You will receive the following result −One Two Three

How to handle Null values while working with JDBC?

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

2K+ Views

SQL's use of NULL values and Java's use of null are different concepts. So, to handle SQL NULL values in Java, there are three tactics you can use:Avoid using getXXX( ) methods that return primitive data types.Use wrapper classes for primitive data types, and use the ResultSet object's wasNull( ) method to test whether the wrapper class variable that received the value returned by the getXXX( ) method should be set to null.Use primitive data types and the ResultSet object's wasNull( ) method to test whether the primitive variable that received the value returned by the getXXX( ) method should ... Read More

How can we retrieve time from a table in JDBC?

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

323 Views

The ResultSet interface provides a method named getTime() this method accepts an integer parameter representing the index of the column, (or, a String parameter representing the name of the column) from which you need to retrieve the time value. To retrieve time value from a table −Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as 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.Execute ... Read More

What are JSTL Core tags in JSP?

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

239 Views

The core group of tags is the most commonly used JSTL tags. Following is the syntax to include the JSTL Core library in your JSP −Following table lists out the core JSTL Tags −S.No.Tag & Description1Like , but for expressions.2Sets the result of an expression evaluation in a 'scope'3Removes a scoped variable (from a particular scope, if specified).4Catches any Throwable that occurs in its body and optionally exposes it.5Simple conditional tag which evalutes its body if the supplied condition is true.6Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by and .7Subtag of that ... Read More

How can we set time in a table in JDBC?

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

225 Views

You can insert time values in SQL using the time datatype, The java.sql.Time class maps to the SQL Time type.The PreparedStatement interface provides a method named setTime(). Using this you can insert time into a table. This method accepts two parameters −An integer representing the parameter index of the place holder (?) to which we need to set date value.A Time object representing the time value to be passed. The constructor of java.sql.Time class accepts a variable of long type representing the number of milliseconds from the epoch (standard base time I.e. January 1, 1970, 00:00:00 GMT).ExampleAssume we have created ... Read More

Advertisements