Found 317 Articles for JDBC

Update a Column in a Table using Java JDBC

Bamdeb Ghosh
Updated on 04-Oct-2023 18:04:18

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

Difference Between Spring DAO vs Spring ORM vs Spring JDBC

Shriansh Kumar
Updated on 17-Aug-2023 09:28:10

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

Difference Between JDBC and Hibernate

Himanshu shriv
Updated on 14-Jul-2020 09:24:01

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

How to escape backslashes in MySQL with JDBC?

AmitDiwan
Updated on 30-Dec-2019 06:17:55

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

Where we should close a connection in JDBC and MySQL?

AmitDiwan
Updated on 12-Dec-2019 07:11:39

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 −

How to handle indexes in JavaDB using JDBC program?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

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

How to drop a table from JavaDB using JDBC?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

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

How to create a table in JavaDB using JDBC?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

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

How to get the list of all drivers registered with the DriverManager using JDBC?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

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

How to de-register a driver from driver manager’s drivers list using JDBC?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

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

1 2 3 4 5 ... 32 Next
Advertisements