Skip to main content

Posts

JDBC FAQ Part11

23:How to iterate the data from Scrollable ResultSet objuect in both forward and backword direction? to iterate the data in forward direction from a ResultSet object we will use the following 2 methods. public Boolean next() public xxx getXxx(int fieldno.)             Where xxx may be byte, short, char, int, long, float, double. To iterate the data in backward direction from Scrollable ResultSet object we will use the following 2 methods. public Boolean previous() public xxx getXxx(int fieldno)             Where previous() is a Boolean method, which can be used to check whether the previous record is available or not, if it is available then cursor will be moved to previous record position. ...

JDBC FAQ Part10

20: What is ment by ResultSet and What are the types of ResultSets are available in JDBC application?             In jdbc applications ResultSets could be classified in the following two ways. On the basis of ResultSet privilizations (Concurancy):-  There are 2 types of ResultSets. Read only ResultSet Updatable ResultSet Read only ResultSet: -   It is a ResultSet, which will allow the users to read the        data only. To refer this ResultSet, we will use the following constant from ResultSet interface.             ...

JDBC FAQ Part9

18: If we use selection group SQL query to executeUpdate() ,what happened? If we use selection group sql query as a parameter to executeUpdate(…) then JVM will send that sql query to the DBE, DBE will fetch the data and send  back to the java application here java application will store the fetched data in the form of ResultSet object. But executeUpdate() is expecting records  updated count value.             Due to this contradiction JVM will rise an exception like java.lang.SQLException. If we handle the above exception properly then we will get ResultSet abject and we will get the data from Database import java.sql.*; class Test { public static void main(String[] args) {             Statement st=null;   ...

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...