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 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");
    }
}

}

code2 :

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;
}

}

print("code sample");
View Answers









Related Tutorials/Questions & Answers:
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
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
Advertisements
how to login form through spring dao module
how to login form through spring dao module  here i want to chek user details in database through form by using spring dao module.please give me some reference example to me
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
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
How create csv format in jsf ?
How create csv format in jsf ?  Dear Friends , Good morning to all of you? I have a problem to create .CSV format in jsf. Actully I have.... I have created a BO for fields of jasper report,and crate a seprate dao
How to connect to dao n bean classes with jsp
How to connect to dao n bean classes with jsp  I have made this edao pkg package edao; import java.sql.Connection; import... = totalvillagearea; } } **how to connect with this edao and ebean pkg with my jsp
How to create an input box?
How to create an input box?  How to create an input box
How to create arrays in JavaScript?
How to create arrays in JavaScript?  How to create arrays in JavaScript
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
how to create frame in swings
how to create frame in swings  how to create frame in swings
how to create notepad in java
how to create notepad in java  how to create notepad in java
how to create session for login
how to create session for login  how to create session for login? how to display uploaded resume and images in the profile
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
How to create form in Swings
How to create form in Swings  How to create registration, login and question form in Java Swing?   Creating different forms in Java Swing - Examples how to create registration form in swing swing login form example
how to create web aplli
how to create web aplli  how to Create a web application using any technology to display 10 most relevant tweets from Twitter in real-time for the keyword "@cldmgc
how to create web aplli
how to create web aplli  how to Create a web application using any technology to display 10 most relevant tweets from Twitter in real-time for the keyword "@cldmgc
how to create a queue - JMS
how to create a queue  Can u please tell me how to create q queue in JMS and also tell me how to write a program to Send a Static Message for JMS Queue ....please i need it urgently
How to Create Keyboard in JAVA
How to Create Keyboard in JAVA  please help me to create On-Screen Keyboard with java and please give me an another idia to make it ..............iam waiting for your help ,think u so much
how to create ipa file
how to create ipa file  Hi, How to .ipa file? Thanks   Hi, Please check the thread Resources have been modified iPhone. Thanks
how to create rdd in pyspark
how to create rdd in pyspark  Hi, I am have to create an RDD from a String in PySpark. How to do this? How to create rdd in pyspark?   Hi, Its easy you can use the following code example: data = sc.parallelize(list
how to create a table
how to create a table  create table tablename (name varchar(10),name.... Use the following query: create table tablename (name varchar(10),address varchar(10)); For more information, visit the following link: Java Create
how to create uiwebview programmatically
how to create uiwebview programmatically  How to create uiwebview programmatically in iPhone application?   Given is the code that will create the WebView programmatically in iPhone.. CGRect webFrame = CGRectMake(0.0
How To Create a Table.
How To Create a Table.  How To Create a Table?   Hi friends, If you want to create a table, you can run the CREATE TABLE statement..._config.php"; $sql = "CREATE TABLE user_info(" . " id INTEGER NOT NULL" . ", name
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
how to create array in r
how to create array in r  Hi, In R Programming how array is created? how to create array in r? Explain me the process of array creation using.... You can create an array with the help of array keyword. Following is an example
How to create options in HTML
How to create options in HTML  How to create options in HTML? Please guide me.   Create options in HTML Code <tr> <td width="30" valign="middle">Gender:</td> <td><select
How to create variable in TensorFlow?
How to create variable in TensorFlow?  Hi, How to create variable... variable, you have to create the TensorFlow variable to use it with TensorFlow graph. Then tf.variable() method is used to create variable in TensorFlow
how to create array in python
how to create array in python  Hi, how to create array in python? I want to create an array in Python and add some values to it. Thanks   Hi, You can create a new array with the code myArray = [] and after
how to create vector in r
how to create vector in r  Hi, What is vector in R programming and how to create vector in r? Provide me some of the example code. Thanks   Hi, Vector in R is created using the key c(). Vector contains data of only
how to create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
how to create servlet
how to create servlet   package com.controller; import... if(request.getParameter("page").equalsIgnoreCase("create...(Exception e) { System.out.println("Error in controller create
How to create a jar file
How to create a jar file  Hello!!!! I have a project which has a multiple classes with database connection(MS-Access) & now i want to make a single executable jar of it... so pls tell me how it will b possible for me
how to create using jsp
how to create using jsp  code 1: <%@ page language="java...; <title>Create New Student</title> </head> <body> <form name="create" method="post" action="<
how to create a xml page
how to create a xml page  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <
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
How sql Queries possible in DAO without creating Database connections - Java Beginners
How sql Queries possible in DAO without creating Database connections  In DAO we are writting sql queries , how it is possible without creating and closing database connections
DAO Classes
DAO Classes  login page code for Dao classes
org.wso2.bpel - ode-dao-hibernate version 1.3.5-wso2v17 Maven dependency. How to use ode-dao-hibernate version 1.3.5-wso2v17 in pom.xml?
dependency? How to use  org.wso2.bpel  - Version 1.3.5-wso2v17 of ode-dao-hibernate in pom.xml? How to use ode-dao-hibernate version 1.3.5-wso2v17... How to add Gradle  dependency? How to use  org.wso2.bpel - ode-dao
com.erudika - para-dao-mongodb version 1.31.0 Maven dependency. How to use para-dao-mongodb version 1.31.0 in pom.xml?
com.erudika  - Version 1.31.0 of para-dao-mongodb Maven dependency? How...? How to use para-dao-mongodb version 1.31.0 in pom.xml? Learn to use... What is Apache Maven? How to create Maven Web Application
com.erudika - para-dao-mongodb version 1.28.0 Maven dependency. How to use para-dao-mongodb version 1.28.0 in pom.xml?
com.erudika  - Version 1.28.0 of para-dao-mongodb Maven dependency? How...? How to use para-dao-mongodb version 1.28.0 in pom.xml? Learn to use... What is Apache Maven? How to create Maven Web Application
com.erudika - para-dao-mongodb version 1.40.4 Maven dependency. How to use para-dao-mongodb version 1.40.4 in pom.xml?
com.erudika  - Version 1.40.4 of para-dao-mongodb Maven dependency? How...? How to use para-dao-mongodb version 1.40.4 in pom.xml? Learn to use... What is Apache Maven? How to create Maven Web Application
com.enterprisemath - em-dao version 1.4.0 Maven dependency. How to use em-dao version 1.4.0 in pom.xml?
com.enterprisemath  - Version 1.4.0 of em-dao Maven dependency? How to use  com.enterprisemath  - Version 1.4.0 of em-dao in pom.xml? How... Gradle  dependency? How to use  com.enterprisemath - em-dao version
org.finra.herd - herd-dao version 0.94.0 Maven dependency. How to use herd-dao version 0.94.0 in pom.xml?
org.finra.herd  - Version 0.94.0 of herd-dao Maven dependency? How to use  org.finra.herd  - Version 0.94.0 of herd-dao in pom.xml? How to use... Gradle  dependency? How to use  org.finra.herd - herd-dao version 0.94.0
springframework - spring-dao version 1.1.2 Maven dependency. How to use spring-dao version 1.1.2 in pom.xml?
springframework  - Version 1.1.2 of spring-dao Maven dependency? How to use  springframework  - Version 1.1.2 of spring-dao in pom.xml? How... How to add Gradle  dependency? How to use  springframework - spring-dao
org.finra.herd - herd-dao version 0.81.0 Maven dependency. How to use herd-dao version 0.81.0 in pom.xml?
org.finra.herd  - Version 0.81.0 of herd-dao Maven dependency? How to use  org.finra.herd  - Version 0.81.0 of herd-dao in pom.xml? How to use... Gradle  dependency? How to use  org.finra.herd - herd-dao version 0.81.0
se.fortnox.reactivewizard - reactivewizard-dao version 14.26.0 Maven dependency. How to use reactivewizard-dao version 14.26.0 in pom.xml?
of reactivewizard-dao in pom.xml? How to use reactivewizard-dao version 14.26.0...? How to use  se.fortnox.reactivewizard - reactivewizard-dao version... is Apache Maven? How to create Maven Web Application in Eclipse
se.fortnox.reactivewizard - reactivewizard-dao version 5.5.0 Maven dependency. How to use reactivewizard-dao version 5.5.0 in pom.xml?
se.fortnox.reactivewizard  - Version 5.5.0 of reactivewizard-dao Maven dependency? How to use  se.fortnox.reactivewizard  - Version 5.5.0 of reactivewizard-dao in pom.xml? How to use reactivewizard-dao version 5.5.0
org.finra.herd - herd-dao version 0.109.0 Maven dependency. How to use herd-dao version 0.109.0 in pom.xml?
org.finra.herd  - Version 0.109.0 of herd-dao Maven dependency? How to use  org.finra.herd  - Version 0.109.0 of herd-dao in pom.xml? How... Gradle  dependency? How to use  org.finra.herd - herd-dao version

Ads