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 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"%>




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 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
Advertisements
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 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
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
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
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
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
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
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
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
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
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
Video Tutorial: How to check if a folder exists in Java through a source code
we can check out if our folder exists in Java by the help of source code...How to check if a folder exists in Java through a source code Java is an all... to byte code that helps to run any Java virtual machine. Java is one of the most
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 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
ModuleNotFoundError: No module named 'check-device-code'
python environment you have to install padas library. You can install check...ModuleNotFoundError: No module named 'check-device-code'  Hi, My... named 'check-device-code' How to remove the ModuleNotFoundError: No module
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
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.
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
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
fetch database value to text box based on selected value my code given below pls correct my code
fetch database value to text box based on selected value my code given below pls correct my code  my Code Given below Pls... help me send correct code for me jsp file... <%@page contentType="text/html" pageEncoding
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
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
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
Need change in code to make website compatible with any browser
website but the problem is the website will open in only IE not any other browser. So i should make changes in code so that website can open in any browser. What...Need change in code to make website compatible with any browser  I
Java Code to Block a website accessed by any browser in windows
Java Code to Block a website accessed by any browser in windows  I want create an application in Java through Netbean IDE to block any website to be accessed by any browser. I also want to display only its html contents. please
Can i write JavaScript code in AjaxResponse Code ?
Can i write JavaScript code in AjaxResponse Code ?  Hai Every Dynamic's We can't write JavaScript code in Ajax Response Code.Why because it takes only html,json,xml response.I tried a lot to create js form in ajax response.It
Need someone to check and modify my simple code - Java Beginners
); } }   Hi Friend, You can use following code: import...Need someone to check and modify my simple code   How to write a class that contains Variables that hold hourly rate of pay, number of hours
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS - Struts
WRITE A CODE IN STRUTS ACTION CLASS FOR CHECK BOXES AND RADIO BUTTONS ... esteemed and talented people.iwould like to write code in struts action class for check boxes and radio buttons and for submit buttons. i have a jsp page which
in the below code two errors are there one at the button onclick atttibute and the next is at the next button
in the below code two errors are there one at the button onclick atttibute and the next is at the next button  <%@ page import="java.sql.*" %> function editRecord(id){ var f=document.form; f.method="post
How to set left and top positions of alert box using JQuery in the below code?
How to set left and top positions of alert box using JQuery in the below code?  <script> $(document).ready(function...;div><br>Customer Contact Details are incomplete, \n Do you want to update
Can find a solution or code for this - XML
Can find a solution or code for this   Develop a java based tool which can be used to build a GUI structure based on the configurations given in the tool. Input XML Folders/Files E.g:Folder for Main Panel Files for required
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
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
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
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
plz help me any one as fast as u can
plz help me any one as fast as u can  A thief Muthhooswamy planned... is the number of metres he can jump (1<=climbUp<=10^10) climbDown... Sample Input 1: 10:1:1:{10} Here Muthooswamy can jump 10 metres height
Can you get a job with Dataquest?
Can you get a job with Dataquest?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can... so that I can learn the topic "Can you get a job with Dataquest?"
Can you make AI in Python?
Can you make AI in Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can you make... learn the topic "Can you make AI in Python?". Also tell me which
Can you build AI with Python?
Can you build AI with Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can you... that I can learn the topic "Can you build AI with Python?". Also tell me
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.
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
can i know the error in this code... am unable to run this code
can i know the error in this code... am unable to run this code  ... System.out.println(arr[i]); } }   You have used incorrect symbol in your code like < >. The for is improper and not completed. Moreover, you have
Check for number of elements exists between the current position and the limit of a buffer.
Check for number of 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... method returns the number of element available in a buffer. Code
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
ajax ?my code is below bt i cundt get it properly   index.html <... will display here</div> </body> </html> print("code sample...) { e.printStackTrace(); } %> 3)For the above code, we have created following table
Can JavaScript code be broken in different lines?
Can JavaScript code be broken in different lines?  Can JavaScript code be broken in different lines

Ads