create dao

create dao

code 1
package com.dao;
import java.sql.*;
import com.beans.*;

public class DbAccess {

    public void createStudent(SampleBean sampleBean) throws SQLException
    {
        Connection con=null;

        try
        {
            con=DbConnect.createConnection();
            PreparedStatement ps=con.prepareStatement("insert into dinstudent values(?,?,?,?,?)");
            ps.setString(1, sampleBean.getFname());
            ps.setString(2, sampleBean.getLname());
            ps.setInt(3, sampleBean.getAge());
            ps.setString(4, sampleBean.getGender());
            ps.setString(5, sampleBean.getPhone());
            ps.executeUpdate();
            System.out.println("Addition Success");

        }
        catch(Exception e)
        {
            System.out.println("Error in create access");
        }
    }
    public SampleBean viewStudent(String fname) throws SQLException
    {

        SampleBean samView=new SampleBean();
        Connection con=null;
        ResultSet rs=null;
        try
        {
            con=DbConnect.createConnection();
            PreparedStatement ps=con.prepareStatement("select * from dinstudent where fname=?");
            ps.setString(1,fname);

            rs=ps.executeQuery();
            while(rs.next())
            {
                String a=rs.getString(1);

                samView.setFname(a);
                samView.setLname(rs.getString(2));
                samView.setAge(rs.getInt(3));
                samView.setGender(rs.getString(4));
                samView.setPhone(rs.getString(5));
                System.out.println("View Success");
            }
        }
        catch(Exception e)
        {
            System.out.println("Error in student view access");
        }
        return samView;
    }
    public void updateStudent(SampleBean sample,String firstname) throws SQLException
    {
        Connection con=null;
        try
        {

            con=DbConnect.createConnection();
            PreparedStatement ps=con.prepareStatement("update dinstudent set fname=?,lname=?,age=?,gender=?,phone=? where fname=?");
            ps.setString(1,sample.getFname());
            ps.setString(2,sample.getLname());
            ps.setInt(3,sample.getAge());
            ps.setString(4,sample.getGender());
            ps.setString(5,sample.getPhone());
            ps.setString(6,firstname);
            ps.executeQuery();
            System.out.println("updated");
        }
        catch(Exception e)
        {
            System.out.println("Error in student update access");
        }
    }
    public void deleteStudent(String deleteName) throws SQLException
    {
        Connection con=null;
        try
        {
            con=DbConnect.createConnection();
            PreparedStatement ps=con.prepareStatement("delete dinstudent where fname=?");
            ps.setString(1,deleteName);
            ps.executeQuery();
            System.out.println("deleted");
        }
        catch(Exception e)
        {
            System.out.println("Error in access Delete");
        }
    }
}


code 2:


package com.dao;
import java.sql.*;

public class DbConnect {


    public static Connection createConnection()
    {
        Connection con=null;
    try
    {
        Class.forName("oracle.jdbc.OracleDriver");
        con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr", "hr");

        System.out.println("Connected");
    }
    catch(Exception e)
    {
        System.out.println("Not Connected");
        e.printStackTrace();
    }
    return con;
    }

}
View Answers

April 2, 2012 at 7:59 AM

public class ConnectionOracle { public Connection OraConn() {

    Connection conn=null;
    try 
    {
        // load the JDBC-ODBC Bridge driver         
        Class.forName(Constants.DRIVERNAME);
        conn =DriverManager.getConnection( Constants.URL,Constants.USERNAME,Constants.PASSWORD );


    }

    catch ( ClassNotFoundException cnfex ) 
    {
        System.out.println("Class not found !! " +cnfex);           
    }
    catch ( SQLException sqlex ) 
    {
        System.out.println("SQL Exception !! " +sqlex);         
        sqlex.printStackTrace();
    }
    catch (Exception ex)
    {
        System.out.println("Exception has occured "+ex);
    }
    return conn;
}

}









Related Tutorials/Questions & Answers:
create dao
create dao  code 1 package com.dao; import java.sql.*; import com.beans.*; public class DbAccess { public void createStudent(SampleBean...) { System.out.println("Error in create access"); } } public SampleBean
how to create dao
how to create dao   code1: package com.dao; import java.sql.*; import com.beans.*; public class DbAccess { public void createStudent(SampleBean...) { System.out.println("Error in create access"); } } public SampleBean
Advertisements
DAO Classes
DAO Classes  login page code for Dao classes
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
DAO Example
DAO Example  Dear Friends Could any one please give me any example of DAO application in struts? Thanks & Regards Rajesh
DAO in Struts
DAO in Struts  Can Roseindia provide a simple tutorial for implementation of DAO with struts 1.2? I a link already exits plz do tell me. Thank you
DAO - JDBC
DAO  what is dao ? and how to use it?  Hi Friend, The DAO is a pattern that provides a technique for separating object persistence and data access logic from any particular persistence mechanism or API. Thanks
create
create  how to create an excel file using java
dao pack
dao pack  package com.tsi.dao; import java.sql.*; import com.tsi.constants.*; public class DaoPack { public static Connection conn = null; public static Connection createConnection() { try
dao pack
dao pack  package com.tsi.dao; import java.sql.*; import com.tsi.constants.*; public class DaoPack { public static Connection conn = null; public static Connection createConnection() { try
CRUD DAO
CRUD DAO  how to create dao for create,read,update and delete?   /* *ConnectionManager * * *Version:1.0 * *Date:25-Nov-2011 * */ package com.student.dao; import java.sql.*; import org.apache.log4j.Logger
dao
ModuleNotFoundError: No module named 'dao'
ModuleNotFoundError: No module named 'dao'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'dao' How to remove the ModuleNotFoundError: No module named 'dao' error
ModuleNotFoundError: No module named 'dao'
ModuleNotFoundError: No module named 'dao'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'dao' How to remove the ModuleNotFoundError: No module named 'dao' error
spring DAO module turorial
spring DAO module turorial  how to integrate springDAO and spring webMVC
implementing DAO - Struts
This tutorial shows, how to create the source code of Dao and DaoImpl class..., exam in 3 days, and just now i found out our lecturer post a demo on DAO... divided into DAO factory Impl,employeeDAOImpl,DAOFactory,EmployeeDAO. "I strongly
Version of spring>spring-dao dependency
List of Version of spring>spring-dao dependency
Version of springframework>spring-dao dependency
List of Version of springframework>spring-dao dependency
Version of co.jufeng>jufeng-dao dependency
List of Version of co.jufeng>jufeng-dao dependency
Version of com.aoindustries>ao-dao dependency
List of Version of com.aoindustries>ao-dao dependency
Version of com.butor>butor-dao dependency
List of Version of com.butor>butor-dao dependency
Version of com.enterprisemath>em-dao dependency
List of Version of com.enterprisemath>em-dao dependency
Version of com.ibatis>ibatis-dao dependency
List of Version of com.ibatis>ibatis-dao dependency
Version of com.smartitengineering>smart-dao dependency
List of Version of com.smartitengineering>smart-dao dependency
What is the DAO Layer in any application?
What is the DAO Layer in any application?  Hi, What is the use of the DAO layer in any application and how to develop it. Explain with the example code. Thanks   The DAO layer is also known as data access layer
ModuleNotFoundError: No module named 'worm-dao'
ModuleNotFoundError: No module named 'worm-dao'  Hi, My Python... 'worm-dao' How to remove the ModuleNotFoundError: No module named 'worm-dao... to install padas library. You can install worm-dao python with following
ModuleNotFoundError: No module named 'dao-deploy'
ModuleNotFoundError: No module named 'dao-deploy'  Hi, My Python... 'dao-deploy' How to remove the ModuleNotFoundError: No module named 'dao... have to install padas library. You can install dao-deploy python
ModuleNotFoundError: No module named 'SQLAlchemy-Dao'
ModuleNotFoundError: No module named 'SQLAlchemy-Dao'  Hi, My... named 'SQLAlchemy-Dao' How to remove the ModuleNotFoundError: No module named 'SQLAlchemy-Dao' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'worm-dao'
ModuleNotFoundError: No module named 'worm-dao'  Hi, My Python... 'worm-dao' How to remove the ModuleNotFoundError: No module named 'worm-dao... to install padas library. You can install worm-dao python with following
ModuleNotFoundError: No module named 'dao-deploy'
ModuleNotFoundError: No module named 'dao-deploy'  Hi, My Python... 'dao-deploy' How to remove the ModuleNotFoundError: No module named 'dao... have to install padas library. You can install dao-deploy python
What is Spring Struts Hibernate DAO Layer?
What is Spring Struts Hibernate DAO Layer?  Hi, explain me the difference in between Spring Struts Hibernate DAO Layer? Thanks   Hi... in the applications. Struts is used as MVC framework and it helps to create UI for the web
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
DAO DTO design pattern
DAO DTO design pattern  Hi,using dao and dto i want to perform insert,update and delete operation.and the data should navigate from 1 frame 2 another.that page should b smthng like this: <%@ page language="java" import
Maven Repository/Dependency: springframework | spring-dao
Maven Repository/Dependency of Group ID springframework and Artifact ID spring-dao. Latest version of springframework:spring-dao dependencies... at: Maven Tutorials What is Apache Maven? How to create Maven
Maven Repository/Dependency: spring | spring-dao
Maven Repository/Dependency of Group ID spring and Artifact ID spring-dao. Latest version of spring:spring-dao dependencies. # Version... is Apache Maven? How to create Maven Web Application in Eclipse? Maven 3
Maven Repository/Dependency: co.jufeng | jufeng-dao
Maven Repository/Dependency of Group ID co.jufeng and Artifact ID jufeng-dao. Latest version of co.jufeng:jufeng-dao dependencies... to create Maven Web Application in Eclipse? Maven 3 Tutorial Convert
Maven Repository/Dependency: com.ibatis | ibatis-dao
Maven Repository/Dependency of Group ID com.ibatis and Artifact ID ibatis-dao. Latest version of com.ibatis:ibatis-dao dependencies... Tutorials What is Apache Maven? How to create Maven Web
Maven Repository/Dependency: org.n52.sensorweb.sos | hibernate-dao
Maven Repository/Dependency of Group ID org.n52.sensorweb.sos and Artifact ID hibernate-dao. Latest version of org.n52.sensorweb.sos:hibernate-dao dependencies...? How to create Maven Web Application in Eclipse? Maven 3 Tutorial
Maven Repository/Dependency: com.googlecode.genericdao | dao-hibernate
Maven Repository/Dependency of Group ID com.googlecode.genericdao and Artifact ID dao-hibernate. Latest version of com.googlecode.genericdao:dao-hibernate... at: Maven Tutorials What is Apache Maven? How to create Maven
Maven Repository/Dependency: com.smartitengineering | smart-dao
Maven Repository/Dependency of Group ID com.smartitengineering and Artifact ID smart-dao. Latest version of com.smartitengineering:smart-dao dependencies... Tutorials What is Apache Maven? How to create Maven Web
Version of com.butor>butor-auth-dao dependency
List of Version of com.butor>butor-auth-dao dependency
Version of com.butor>butor-attrset-dao dependency
List of Version of com.butor>butor-attrset-dao dependency
Version of com.butor>butor-portal-dao dependency
List of Version of com.butor>butor-portal-dao dependency
Version of com.erudika>para-dao-mongodb dependency
List of Version of com.erudika>para-dao-mongodb dependency
Version of com.gammapeit>generic-injected-dao dependency
List of Version of com.gammapeit>generic-injected-dao dependency
Version of com.smartitengineering>smart-abstract-dao dependency
List of Version of com.smartitengineering>smart-abstract-dao dependency
DAO Layer explained
DAO Layer explained       In this section we will explain you the DAO Layer of our application.   DAO Layer Explained  ADS_TO_REPLACE_1 DAO

Ads