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



Home Answers Viewqa Struts can you check below code if any erors
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


madhu
can you check below code if any erors
0 Answer(s)      5 months and 20 days ago
Posted in : Struts


database.java

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

package com.test;

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List;

public class Database {

public List getUsers() throws SQLException,Exception{


    List list = new ArrayList();
    ResultSet rs  = null;
    javabean b = null;
    Connection conn = null;
    Statement stmt = null;

    try{

  Class.forName("com.mysql.jdbc.Driver");

  conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","root","mysql");

  stmt = conn.createStatement();
  String sql;
  sql = "SELECT user_id, name,lname,fname FROM mydatabase.test_users";
   rs = stmt.executeQuery(sql);

        while(rs.next()){
            b = new javabean();
            b.setName(rs.getString("name"));
            b.setFname(rs.getString("fname"));
            b.setLname(rs.getString("lname"));
            b.setUserId(rs.getString("user_id"));
            list.add(b);

        }
    }catch(SQLException  e){
        System.out.println("Exception occured"+e.getMessage());
        throw new  SQLException(e);
    }
    finally{
        if(conn!=null)
            conn.close();
        if(stmt!=null)
            stmt.close();
        if(rs!=null)
            rs.close();

    }
    return list;


}

public List addUsers(javabean bean) throws SQLException,Exception{


    List list = new ArrayList();
    ResultSet rs  = null;
    javabean b = null;
    Connection conn = null;
    Statement stmt = null;

    try{

  Class.forName("com.mysql.jdbc.Driver");

  conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","root","mysql");

  stmt = conn.createStatement();

  String sql;
  sql = "insert  into mydatabase.test_users(name,fname,lname) values('"+bean.getName()+"','"+bean.getFname()+"','"+bean.getLname()+"');";
   stmt.execute(sql);

    //conn.commit();
    }catch(SQLException  e){
        System.out.println("Exception occured"+e.getMessage());
        throw new  SQLException(e);
    }
    finally{
        if(conn!=null)
            conn.close();
        if(stmt!=null)
            stmt.close();
        if(rs!=null)
            rs.close();

    }
    return list;


}

}

action class

package com.test;

import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction;

public class TestAction extends DispatchAction{

   public ActionForward get(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Database d =  new Database();
    try {
         List list =  d.getUsers();
         request.setAttribute("list", list);


    } catch (Exception e) {
    }

    return mapping.findForward("display");
}

   public ActionForward add(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    HttpSession session = null;
    try {

        session = request.getSession();

    } catch (Exception e) {
    }

    return mapping.findForward("add");
}


   public ActionForward insert(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        Database d = new Database();
       javabean b =  new javabean();
       b.setName(request.getParameter("name"));
       b.setFname(request.getParameter("fname"));
       b.setLname(request.getParameter("lname"));
    try {
            d.addUsers(b);


    } catch (Exception e) {
    }

    return mapping.findForward("save");
}



   public ActionForward delete(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    HttpSession session = null;
    try {

        session = request.getSession();

    } catch (Exception e) {
    }

    return mapping.findForward("delete");
}

}

adduser.jsp

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

View Answers

Related Tutorials/Questions & Answers:
can you check below code if any erors
can you check below code if any erors  database.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template
Can you suggest any good book to learn struts
Can you suggest any good book to learn struts  Can you suggest any good book to learn struts
Advertisements
can any one give the frogort password code using jsp,
can any one give the frogort password code using jsp,  plz give the code for frogot password
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  Q 1) In a class first day 25 students are joined. After two days that total students will increased to 60. We can develop a program by using ArrayList concept
can any one explain this
can any one explain this  class Clidder { private final void flipper() { System.out.println("Clidder"); } } public class Ex3 extends Clidder { public final void flipper() { System.out.println
Check for any elements exists between the current position and the limit of a buffer.
Check for any elements exists between the current position and the limit of a buffer. In this tutorial you will see how to check for existence of any... and returns false when there is no element available in the buffer. Code
Can any one please help me in this ,,,,,,, need java code for this ,,,,please anyone
Can any one please help me in this ,,,,,,, need java code for this ,,,,please anyone  The Airport Valet Parking Company (AVP) is a company which provides a convenient medium cost parking solution to users of a local airport. Key
Save a pdf with spring as below code
Save a pdf with spring as below code   c:/report.pdf All work in the same way, but never save the report to disk. How to solve this problem? please reply me
check youtube iframe code
check youtube iframe code  I have a piece of code that checks the youtube embed code in this format: My PHP code looks like this now: //Check Embed Code $embedCode = $postData['embedCode
Check for any elements exists between the current position and the limit of a double type buffer.
Check for any elements exists between the current position and the limit of a double type buffer. In this tutorial you will see how to check for existence of any element between the current position and the limit of a buffer
I want code below mention programe
I want code below mention programe  Create a web application using any technology that accepts a keyword and displays 10 relevant tweets from Twitter in real-time for that keyword
Please can you help
Please can you help  I have a some code which uses a textarea comment...; Please could you change the code so it will do this Please. Many thanks. Colin... it on. However I wanted it to be able to check for a existing comment and create
how to write a programm in C for included code below
. In the session, you can run SQL queries interactively. The query results are presented in XML. A '.quit' command ends the session. Below is an example session...how to write a programm in C for included code below  Here is my
can you explain ?
(); } } iam explain whole code exept this part can you help...can you explain ?  my dear can you teel me the explaintion for this code i need it GregorianCalendar cal = new GregorianCalendar(y, m, 0
How many objects are created in the code below? Explain.
How many objects are created in the code below? Explain.  Hi, Here is my code public static void main(String[] args) {String s1 = "abc"; StringBuffer s2 = new StringBuffer(s1); StringBuffer s3= s2; StringBuffer s4 = new
Please tell me the code to generate the below structure
Please tell me the code to generate the below structure  1 2 3 4 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 7 8 9 1 2 8 9 1 9 1 2 8 9 1 2 3 7 8 9 1 2 3 4 6 7 8 9 1 2 3
Can you correct this codes?
Can you correct this codes?  Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 4 at searchcon.(searchcon.java:39) at search.initComponents(search.java:41) at search.(search.java:7) at payroll
dojo check tree code - Ajax
dojo check tree code  Hi..Boss Thanks for ur site. it helped me so many times.. my problem is while trying to use dojo tree with check boxes facing some issues i tried with two examples but i failed to do that http
Any one can help me? - Java Beginners
Any one can help me?  CAN any of u help me to do this java codes for the interface given below? thanku the user will be given jumbled words.... If the player is able to arrange all the words without any mistake, he/she can get
Please , can any one answer this Question?
Please , can any one answer this Question?  How to cummunicate one web application to another web application in different places
Can you help me with applet?
Can you help me with applet?  I'm very new to applet, and i'm weak in graphic design part. How can i add the graphic in my test project? Can you help me with this: import java.io.*; import java.util.*; import javax.swing.
pl z provide code for below question in javascripr or jsp - JSP-Servlet
pl z provide code for below question in javascripr or jsp  Once the parallel request happened, the user will not be able to continue his work, until the first request ends by itself and back to the home page   Hi
Applet run with appletviewer but not in browser, any code problem.
can be problem in code also. please check my code. 1) Card.java package...Applet run with appletviewer but not in browser, any code problem.  ... as java applet its working, but not on browser. Please check can I call
check
updated"); will the above code check if the user has entered value for empcode and password variables.Explain the code... code,String pass) { this.empcode=code; this.password
how can you calculate you your age in daies??
how can you calculate you your age in daies??  **hi, I am beginner in java! can any one help me to write programm to calculate age in daies...."); } } Hope that the above code will be helpful for you. Thanks
If You Prefer A Writer Having The Finest Credentials And Highest Qualifications, Check This Out!
If You Prefer A Writer Having The Finest Credentials And Highest Qualifications, Check This Out!      ... to accomplish their task. If you are looking for some extremely inspirational words
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books... Vidya  Hi Friend, Try the following code: import java.util.
Can a abstract class be defined without any abstract methods?
Can a abstract class be defined without any abstract methods?   hi, Can a abstract class be defined without any abstract methods? thanks
what is cloud computing? any how we can implement?
what is cloud computing? any how we can implement?  what is cloud computing? any how we can implement
How many cookie object we can store in a session? is there any limit?
How many cookie object we can store in a session? is there any limit?  How many cookie object we can store in a session? is there any limit
 

 

 

DMCA.com