- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
170 Views
Introduction Updating a column in a database table is a relatively frequent activity in software development. Java Database Connectivity (also known as JDBC API), which serves as a link between Java programmers and databases like MySQL, may be used to carry out this task in Java. Using the JDBC API, we may establish a connection to the database, get data from tables, and carry out a number of tasks, including altering columns. We will talk about how to update a column in a table using Java JDBC. We will start by make a connection to the database and then we ... Read More
372 Views
The given three terms Spring DAO, Spring ORM and Spring JDBC, are related to Data Access in Spring Framework. This framework was developed in June 2003 by Rod Johnson and with its release, it became very famous among Java developers because of its comprehensive set of tools and features for building enterprise applications. Although these terms serve the same purpose there exist a few distinctions between them. In this article, we are going to discuss the difference between Spring DAO, Spring ORM and Spring JDBC. Spring DAO vs Spring ORM vs Spring JDBC In this section, we will introduce the ... Read More
4K+ Views
JDBC is acronym of Java database connectivity. It is used to connect your application to the database and transactions . It is an open source Java api. Hibernate is also used for connect your application to database and to do database related transactions but with different approach. It has a object relationship library which mapped the tables and columns of the database with the java object. It enables object oriented programming in database. Hibernate provides HQL to access the data from the database. Sr. No.KeyJDBCHibernate1Basic It is database connectivity technology It is a framework, 2Lazy Loading It does not support lazy loading Hibernate support ... Read More
286 Views
To escape backslashes, use PreparedStatement while inserting records. Let us first create a table −mysql> create table DemoTable1904 ( ClientId int, ClientName varchar(20), ClientAge int ); Query OK, 0 rows affected (0.00 sec)The Java code is as follows −import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class EscapeBackslashesDemo { public static void main(String[] args) { Connection con = null; PreparedStatement ps = null; try { con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?" + "useSSL=false", "root", "123456"); String query = "insert into DemoTable1904(ClientId, ... Read More
974 Views
You need to close connection in finally block. Following is the Java code to close connection in JDBC and MySQL −import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class CloseConnectionDemoInFinallyBlock { public static void main(String[] args) { String JDBCURL = "jdbc:mysql://localhost:3306/web?useSSL=false"; Connection con = null; try { con = DriverManager.getConnection(JDBCURL, "root", "123456"); System.out.println("connection is open"); } catch (Exception e) { e.printStackTrace(); } finally { try { con.close(); } catch (SQLException sqlException) { sqlException.printStackTrace(); } } } }This will produce the following output −connection is openHere is the screenshot of the output −
717 Views
Indexes in a table are pointers to the data, these speed up the data retrieval from a table. If we use indexes, the INSERT and UPDATE statements get executed in a slower phase. Whereas SELECT and WHERE get executed with in lesser time.Creating an indexCTREATE INDEX index_name on table_name (column_name);Displaying the IndexesSHOW INDEXES FROM table_name;Dropping an indexDROP INDEX index_name;Following JDBC program creates a table with name Emp in JavaDB. creates an index on it, displays the list of indexes and, deletes the created index.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class IndexesExample { public static void main(String ... Read More
104 Views
You can create a table in a database using the CREATE TABLE query.SyntaxCREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) );To create a table in 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 using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement − Create a Statement ... Read More
118 Views
You can create a table in JavaDB database using the CREATE TABLE statement.SyntaxCREATE TABLE table_name ( column_name1 column_data_type1 constraint (optional), column_name2 column_data_type2 constraint (optional), column_name3 column_data_type3 constraint (optional) );To create a table in JavaDB using JDBC API you need to −Register the driver − The forName() method of the class, Class accepts a String value representing a class name loads it in to the memory, which automatically registers it. Register the driver using this method.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) ... Read More
737 Views
The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.One way to register a driver class object to Driver manager is the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);List of all the DriversYou can get the list of all the drivers registered ... Read More
419 Views
The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.You can register a new Driver class in two ways −Using the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);Using the forName() method of the class named Class. To this method you need to ... Read More