Search This Blog

Sunday, September 27, 2009

some more things about hibernate before downloading presentation and material
common interview question about hibernate
what are the interfaces used in hibernate name them?
The five core interfaces are used in just about every Hibernate
application. Using these interfaces, you can store and retrieve
persistent objects and control transactions.
Session Interface
SessionFactory Interface
Configuration Interface
Transaction Interface
Query and Criteria Interface

the power point slide,ppt you can download from here
download

Saturday, September 26, 2009

part-2 click above links for more information on hibernate
or here
Hibernate3.2 with struts tutorial and assignment

Checking if objects are identical
Java defines two notations:
Object identity [==]
Equality of value [.equals()]
In SQL it is just checking if the two primary keys are the same.
Two or more objects can represent the same row of data.
Problem with SQL surrogate keys

>>what is Object Graph Navigation you will know in this presentation(power point slide ppt)

>>>>what is Object/relational Mapping (ORM)
ORM is the automated & transparent persistence of Java objects to tables in a RDBMS.

Metadata describes the mapping between the objects and the database.

ORM works by transforming data from one representation to another

Contains the following parts
API for CURD operations on objects

API for queries for classes & properties

Facility for mapping metadata

Technique for interaction with transactional objects

more info click below

part-1 hibernate

All about hibernate tutorial,presentation,assignment from cdac original post

all information about cdac training,diploma for cdacnoida,cdac mohali,cdac centers location,cdac entrance exam preparation

Mainly for dabc,dac,acts,cdac.in,cdac 2009

hibernate 2,hibernate 3.2.5,hibernate 3.2.6,hibernate 3.3,hibernate 3.3.1,hibernate apache,hibernate architecture,hibernate bean,hibernate component,hibernate configuration,hibernate createquery,hibernate discriminator,hibernate formula,hibernate hbm.xml,hibernate index,hibernate inner join,hibernate interface,hibernate jdeveloper,hibernate left join,hibernate like,hibernate loading,hibernate name,hibernate optimistic locking,hibernate overview,hibernate pattern,hibernate persistence.xml,hibernate plugin,hibernate presentation,hibernate project,hibernate query,hibernate session.save,hibernate source,hibernate spatial,hibernate statistics,hibernate union,hibernate unique,hibernate uniqueresult,hibernate usertype,hql hibernate,install hibernate,jdbc hibernate,native hibernate,pojos action,servlet hibernate


It includes
1)What is persistence?
The paradigm mismatch
Persistence layers and alternatives
Object/relational mapping

2)what is Paradigm Mismatch definition..?
Problems caused when objects need to be stored in relational tables.
Granularity
Subtypes
Identity
Associations
Graph Navigation


3)Problem of Granularity
Objects can have various kinds of granularity (structure ??) to its data.
Poor support for used defined types (UDT) in SQL.
No implementation is portable.
Forces developers to use less flexible representations on the object model

4)hibernate Problem of Subtypes
Java objects implements inheritance (super & sub classes).
Each sub or super class will define different data & completely different functionality.
An object can be associated with objects of different classes, but of same type (polymorphism).
SQL provides no support for inheritance or polymorphism

continue to next post

Wednesday, September 16, 2009

solutions for jdbc assignment,examples jdbc,prepared statement,jdbc connectivity with msaccess,mysql and oracle example

example consist of type1 type2 type3 and type4 driver

jdbc1 example
import java.sql.*;
import java.io.*;

public class JDBC1
{
public static void main(String[] args) throws ClassNotFoundException,SQLException,IOException
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:odbc:name","scott","tiger");
Statement stmt=con.createStatement();
DataInputStream dis=new DataInputStream(System.in);
try{ while(true)
{
ResultSet rs=stmt.executeQuery("select * from emp");

System.out.println("Please enter the name of the column to be fetched");
String col=dis.readLine().trim();
System.out.println(col);
if(col==null)
break;
rs.next();
while(rs.next())
{
System.out.println(rs.getString(col)+" "+rs.getString(2));
}
}}catch(Exception e)
{System.out.println("error while entering");
}
}
};

jdbc example2 connecting with mysql
import java.sql.*;


public class JDBC2
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/shob","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from login");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

jdbc example 3 with wamp sql little change
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Wampsql {
public static void main(String args[]) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
String url;
url ="jdbc:mysql://localhost/shob" ;

String user, pass;
user = "root";
pass = "";

Connection con;
Statement stmt;
ResultSet rs;

try {
con = DriverManager.getConnection(url, user, pass);
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM login");

// Get the resultset ready, update the passwd field, commit
//rs.first();
//rs.updateString("message_text", "updated");
//rs.updateRow();
System.out.println(rs.getString(1));

rs.close();
stmt.close();
con.close();
} catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}

jdbc example 1 more driver

import java.sql.*;

public class JDBC4
{
public static void main(String[] args) throws ClassNotFoundException,SQLException
{
String serverName="esurakshaxp4";
String portNumber="1521";
String sid="oracle";
String url="jdbc:oracle:thin:@"+serverName+":"+portNumber+":"+sid;
//String url="jdbc:mysql://localhost/quality_assurance_lms";
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con=DriverManager.getConnection(url,"scott","tiger");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
}
}

solutions for assignment posted update salary

import java.sql.*;
import java.io.*;

public class UpdateTest
{
public static void main(String[] args)
{
try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dabctest","scott","tiger");
Statement st=con.createStatement();

DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter the Employee name :");

System.out.flush();
String str=dis.readLine();

System.out.println("Enter Salary :");
System.out.flush();
int newsal=Integer.parseInt(dis.readLine().trim());

int i=st.executeUpdate("update emp set sal="+newsal+" where ename='"+str+"'");
//System.out.println("update emp set sal="+newsal+" where ename='"+str+"'");
System.out.println("No of Rows Updated :"+i);
con.close();

}catch(Exception e)
{
System.out.println(e);
}

}
}


this is for prepare statement example and assignment solution
import java.io.*;
import java.sql.*;

public class PrepareTest
{


public static void main(String[] args)
{
Connection con=null;
PreparedStatement pst=null;
ResultSet rs=null;
DataInputStream dis=null;
try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:dabctest","scott","tiger");
// Class.forName("com.mysql.jdbc.Driver");
//String s="jdbc:mysql://localhost/eSikshak1";
//con=DriverManager.getConnection(s,"root","");
pst=con.prepareStatement("Select * from emp where empno= ? and ename= ?");

dis=new DataInputStream(System.in);
while(true)
{
System.out.println("Enter the empno number :");
System.out.flush();
int eno=Integer.parseInt(dis.readLine().trim());
String enam=dis.readLine().trim();
if(eno==0)
break;
pst.setInt(1,eno);
pst.setString(2,enam);
rs=pst.executeQuery();


while(rs.next())
{
String enumber = rs.getString(1);
String ename = rs.getString(2);
System.out.println(enumber);
System.out.println(ename);

}
}
pst.close();
con.close();
}catch(Exception e)
{
System.out.println(e);
}

}
}


rest if some one needed post in comment please

jdbc assignment beginners question solved and unsolved with solution or without

1. Implement
(a)Type 1 Driver and connect to the Oracle.
(B)Type2 Driver
(b)Type 3 Driver using IDS server and connect to mdb or oracle.
(c)Type 4 Driver and connect to Oracle and MySQL.

2. Implement Type-4 driver with
(a) Statement
(b) PreparedStatement
(c) CallableStatement

3. Use PreparedStatement to fetch results based on the some input taken from user inside a loop.

4. Use CallableStatement to call a stored procedure which takes empno and increment (salary) of that employee, as input, and returns the incremented salary as the output.

6. Write a program which takes input as the empno and salary.
a.) If the empno already exist and salary>2000, update the salary of the employee.
b.) If the empno doesn’t exist, ask for the all other column values in that table, retrieved using metadata programming.
c.) Insert empno and other values taken as input as part of (b.)
d.) If hiredate of employee is before year 1981, delete the record from the table.

7. Write a program to show use of all the methods for the Scrollable and Updatable ResultSets.

you will find solution on my next post

PART-3 JDBC TRANSACTION MANAGEMENT

post consist of

1)jdbc transaction
2)Transaction Management
3)what is setAutoCommit?
4)JDBC Cursor Types
5)ResultSet type
6)ResultSet concurrency issue in jdbc
download the presentation ppt or power point from here
download presentation jdbc

7)TYPE_FORWARD_ONLY
8)TYPE_SCROLL_INSENSITIVE
9)TYPE_SCROLL_SENSITIVE
10)CONCUR_READ_ONLY,CONCUR_UPDATABLE
11)Result Set Methods next,previous,first,last,beforeFirst,afterLast,relative(),absolute all are methods
12)resultset can be updatable,scrollable,update process,insertion process
13)resultset meta data

PART2-JDBC API,jdbc tuorial and example

post consist of basic jdbc api,javadatabase connectivity api ,presentation,tutorial,jdbc question and assignment and jdbc examples
here is the content what this jdbc ppt will consist
1)The JDBC API is available in the java.sql and javax.sql packages
2)JDBC classes, interfaces and exceptions
3)DriverManager,Connection,PreparedStatement and CallableStatement objects
4)Statement-retrieve ResultSet object
5)SQLException
7)Seven Steps For Using JDBC
Load The Driver
Define connection URL
Establish the connection
Create a statement object
Execute Query
Process the result
Close the connection.
8)JDBC Object Classes
9)JDBC Class Usage
10)The Flow Diagram
11)Loading/Registering A Driver
12)JDBC URLs
13)jdbc code and program Example

download link for jdbc api presentation
download

Part1-jdbc cdac presentation

this post consist of jdbc cdac presentation contain jdbc tutorial
Like to tell you what is the content of the presentation (ppt,power point presentation)
JDBC stands for "Java DataBase Connectivity".

1)jdbc itroduction and JDBC Ancestry
2)Who develops JDBC Specification
3)Why use JDBC
4)JDBC Architecture
5)JDBC Drivers
Type I: “Bridge” JDBC-ODBC Bridge sun.jdbc.odbc.JdbcOdbcDriver
translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver
Type II: “Native” Native-API/partly Java Driver
This type of driver converts JDBC calls into calls to the client API for that database
Type III: “Middleware” Net-protocol/all-Java driver
the net-protocol/all-Java driver -- follows a three-tiered
Type IV: “Pure” Native-Protocol Driver the Direct to Database Pure Java Driver

so the first presentation consist of jdbc introduction
download presenation
download

6)