• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JDBC basics

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear friends,
i am new to JDBC,just trying out with my steps in JDBC.can any one of u explain me how the following lines work?


class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc sn");
Statement st=con.createStatement();
Resultset rs=st.executeQuery("select * from table");

i want to know about the interfaces,classes and where the methods of these interfaces are implemented.awaiting ur reply,
regards,
raja
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raja ,

Driver is an interface defined in java.sql package. Implementation will be provided by the respective vendors of the database.

Implementation of Driver will include how to communicate/connect with the database, how to pass data to and from database to java program and vise-versa etc.,

If you are using DriverManager to manage your connection objects, you need to load the Driver in to the memory. That�s why you execute the statement Class.forName(�Driver Name�);When you load any driver, it will register itself with the DriverManager.

DriverManager is a class in which getConnection is a static method which helps to achieve connectivity with corresponding database mentioned within it.

Connection , an interface in java.sql, provides methods for 3 type of SQL queries -
1. creatStatement - for simple query- return type is Statement interface
2.prepareStatement -for prepared query - retrun type is PreparedStatement Interface
3. prepareCall - for stored procedure and function - return type is CallableStatement

Statement , an Interface in java.sql , provides 3 types of methods again -1. executeQuery - return type ResultSet - for database query (select statements)
2. executeUpdate - return type int(no. of rows updated) - for insert ,update , delete operation of databese
3. execute - return type is boolean - true if ResultSet is returned and false if no. of Updated rows is returned - used for all type of database operation .

ResultSet ,an Interface in java.sql. , provides few methods like getMetaData() .


Please let me know whether your doubts are clear or not .
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our JDBC forum...
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic