Skip to main content

Posts

JDBC FAQ Part8

16:Ingeneral execute() method can be used to execute selection group SQl queries for getting the data from Database , but execute() return a boolean value true so here how it possible to fetch the data from database? Execute() can be used to execute both selection group sql query and updation group sql query. If we use execute() to execute a selection group sql query then DBE(Database engine) will execute that sql query and  send back the fetched data from database to java application. Now java application will prepare a ResultSet object with the fetched data but execute() will return “true” as a Boolean value. At this situation to get the reference of the ResultSet object explicitily, we will use the following method from Statement object.                  ...

JDBC FAQ Part7

14: How to delete records from  a table  from  jdbc application?. import java.sql.*; public class DeleteTableEx {    public static void main(String[] args)throws Exception    {             Class.forName(“oracle.jdbc.driver.OracleDriver”); Connection con = DriverMadoeer.getConnection(“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”jhon”);             Statement st = con.createStatement();             int updateCount = sst.executeUpdate(“delete from emp3 where esal>=7000”);             System.out.println(“records deleted………”+updateCount);         ...

JDBC FAQ part5

10:  What are the differences between executeQuery(…), executeUpdate(…) and execute(…)        methods? Ans:     where executeQuery() can be used to execute selection group sql queries to fetch the data from database. When we use selection group sql query with executeQuery() then JVM will send that sql query to the database engine, database engine will execute it, by this database engine(DBE) will fetch the data from database and send back to the java application. Java is a purely object oriented technology. That’s why the jdbc application will maintain the fetched data from database, in the form of an object at heap memory, called as ResultSet object.              public  ResultSet executeQuery(String sqlquery)             where executeUpdate() can be used to execute updation group sql query to update the d...

JDBC FAQ Part6

12: How to insert records into a table from a JDBC application? import java.sql.*; import java.io.*; public class InsertTableEx {    public static void main(String[] args) throws Exception    {             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));             Class.forName(“oracle.jdbc.driver.OracleDriver”); Connection con  =               DriverMadoeer.getConnection(“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”jhon”); Statement st = con.createStatement(); while(true) {             System.out.println(“Enter emp number”);             Int eno = Integer.parseInt(...

JDBC FAQ part4

6:    How to establish a Database connection between java application and Database? If we want to establish a connection between java application and the database we will the following piece of code. Connection con= DriverMadoeer.getConnection(“jdbc:odbc:doe”,”doe”,”system”,”madoeer”); Where getConnectin() is a static method from DriverMadoeer class, which can be used to return connection object. 7:    Basically Connection is an interface, how getConnection() will create an object for       Connection interface? Ans:    Connection is an interface from java.sql package, for which getConnection(_)  was return an anonymous inner class object of the Connection interface. ...

JDBC FAQ part3

4: What is JDBC and What are the steps to write a JDBC application?        The process of interacting with the database from a java application is called as JDBC(Java Database Connectivity) To interact with the database from a java application we will use the following five   steps. load and register the driver. Establish a connection between java application and the database. prepare either statement object or PreparedStatement object or CallebleStatement object as per the application requirements. write and execute the SQL queries. terminate the connection which we have established. 5:  How to load a JDBC driver?   In general sun Microsystems  has provided Driver interface for this all the database vendors has provided their own implementation. If we want to use the database vendor provided Driver implementation to our JDBC application, first we need to make the availability of the respective Driver’s   ....

JDBC FAQ part2

3: What is  Driver? How many Drivers are available in JDBC? What are the types?    It is a process of interacting with the database from a java application. In JDBC applications we must specify the complete database logic in java application as for the java API representations, later on, we need to send java represented database logic to the database engine(DBE). DBE must execute the database logic but it was configured as per the java representations but DBE able to understand only Query Language representations. At the above situation, if we want to execute our database logic, we need to use one interface in between java application and the database, that interface must convert java representations to query language representations and query language representations to j...