Found 316 Articles for JDBC

Difference Between JDBC and ODBC

AmitDiwan
Updated on 25-Mar-2021 06:24:33
In this post, we will understand the difference between JDBC and ODBC.ODBCIt stands for Open Database Connectivity.It was introduced by Microsoft in the year 1992.It can be used with languages such as C, C++, Java.It can be chosen only on windows platform.Its drivers are developed in native languages such as C, C++.It is procedural.It is not recommended to use this for Java applications.It is because the performance would be reduced due to internal conversions, and it would become platform dependentJDBCIt stands for Java Database Connectivity.It was introduced by SUN Micro Systems in the year 1997.It can only be used only ... Read More

Difference Between JDBC and Hibernate

Himanshu shriv
Updated on 14-Jul-2020 09:24:01
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
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
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
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
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
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
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
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

How to write data into BLOB and CLOB type columns in a table using JDBC?

Smita Kapse
Updated on 30-Jul-2019 22:30:26
CLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).Inserting Data into a column of Clob typeYou can insert a CLOB type value using the setCharacterStream() or, ... Read More
1 2 3 4 5 6 7 ... 32 Next
Advertisements