JDBC Statement creates a table example

The JDBC statement is used to execute queries against the database. Let us study JDBC Statement by create table example. Example: JDBCTest.java import java.sql.Connection; import java.sql.Statement; import com.w3schools.util.JDBCUtil;   /** * This class is used to create a table in DB. * @author w3schools */ public class JDBCTest { public static void main(String args[]){ Connection … Read more

JDBC Statement interface

The JDBC statement is used to execute queries against the database. Statement is an interface which provides the methods to execute queries. We can get a statement object by invoking the createStatement() method of Connection interface. Syntax: Statement stmt=conn.createStatement(); Commonly used methods of Statement interface: 1. execute(String SQL): It is used to execute SQL DDL statements. … Read more

Connect to MySql database with JDBC driver

To connect with MySql database with JDBC driver follow the same basic steps discussed in previous tutorials. We have to know the following information to connect with MySql database: 1. Driver class: com.mysql.jdbc.Driver. 2. Connection URL: Syntax: “jdbc:mysql://hostname:port/dbname”,”username”, “password” Connection url for MySql database: jdbc:mysql://localhost:3306/w3schools where 3306 is the port number and w3schools is the … Read more

Connect to Oracle database with JDBC driver

To connect with oracle database with JDBC driver follow the same basic steps discussed in previous tutorials. We have to know the following information to connect with oracle database: 1. Driver class: oracle.jdbc.driver.OracleDriver. 2. Connection URL: Syntax: “jdbc:oracle:thin:@localhost:port:serviceName”,”username”, “password” Connection url for MySql database: jdbc:oracle:thin:@localhost:1521:xe where 1521 is the port number and XE is the … Read more

Steps to connect database in java

Steps to connect database in java using JDBC are given below: Load the JDBC driver. Connection. Statement. Execute statement. Close database connection.   1. Load the JDBC driver: First step is to load or register the JDBC driver for the database. Class class provides forName() method to dynamically load the driver class. Syntax: Class.forName(“driverClassName”); To … Read more

Java FilterConfig interface

FilterConfig object is created and used by the web container to pass init parameters to a filter during initialization. Methods of FilterConfig interface: 1. getFilterName(): Returns the name of the filter defined in web.xml. Syntax: public String getFilterName() 2. getInitParameter(String name): Returns the value of the specified parameter. Syntax: public String getInitParameter(String name) 3. getInitParameterNames(): … Read more

Servlet HttpSession

HttpSession: HttpSession is an interface that provides a way to identify a user in multiple page requests. A unique session ID is given to the user when the first request comes. This ID is stored in a request parameter or in a cookie. How to get a session object? HttpServletRequest interface’s getSession() method is used … Read more

URL rewriting in servlet

URL rewriting: URL rewriting is a way of appending data at the end of a URL. Data is appended in name-value pair form. Multiple parameters can be appended in one URL with name-value pairs. Syntax: URL?paramName1=paramValue1& paramName2=paramValue2 How to get the parameter value from url in the servlet? HttpServletRequest interface’s getParameter() method is used to get … Read more

Servlet Hidden fields

Hidden field: Hidden field is an input text with hidden type. This field will not be visible to the user. Syntax: input name=”fieldName” value=”fieldValue” type=”hidden” How to get hidden field value in servlet? HttpServletRequest interface’s getParameter() method is used to get hidden field value in servlet. Syntax: String value = request.getParameter(“fieldName”);   Note: Hidden field only works … Read more