Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


meena n
how to create dao
0 Answer(s)      2 years and 9 months ago
Posted in : Java Interview Questions


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

Advertisement
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 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 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
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
DAO Example
DAO Example  Dear Friends Could any one please give me any example of DAO application in struts? Thanks & Regards Rajesh
spring DAO module turorial
spring DAO module turorial  how to integrate springDAO and spring webMVC
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
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 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
dao
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
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 create notepad in java
how to create notepad in java  how to create notepad in java
how to create frame in swings
how to create frame in swings  how to create frame in swings
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 an input box?
How to create an input box?  How to create an input box
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 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 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
Advertisements
 

 

 

DMCA.com