Jsp and mysql... best aproach

hi all ! I need to do some checking of some data before submiting my form. So my idea is that depending on what you select in a list/ menu the values of another list changes. I know I could do this with javascript. The problem is that I want to make the values from the second list reflect data that is stored in a database.
So how can I do this ?
Any advice, recomendations, links are apreciated.

Me, I would put an onChange event on the first select box that submits a form to retrieve the content of the second select box.
There are ways to do it without a submit though:
1) dynamic select box. It involves putting all possible values for the second select box into a huge javascript array and you use the first select box to index into this array.
2) Ajax. With ajax you can fetch the data for the second select box in the background.
3) hidden iframe. If you don't want to use ajax directly you could load a page in a hidden iframe that will mimic the ajax call.
For all three options there are numerous articles on the web, just search for them.

Similar Messages

  • JSP and MySql Connectivity in Fedora core 4

    Dear all,
    We are developing software using JSP and MySql on Fedora Core 4 platform and are unable to find the connectivity for JSP and MySql. Can anybody help....

    Dear all,
    We are developing software using JSP and MySql on Fedora Core 4 platform and are unable to find the connectivity for JSP and MySql. Can anybody help....

  • Unable to connect JSP and MySQL

    Hi, I am new to this forum
    I've started developing web pages using JSP
    I've the problem connecting JSP and MySQL database. I've created the page that retrive records from mysql table. But the connection fail to access to database it gives me this error:
    org.apache.jasper.JasperException: Exception in JSP: /retreive_book.jsp:15
    The code is:
    12: <%
    13: //Class.forName("com.mysql.jdbc.Driver").newInstance();
    14: Class.forName("org.gjt.mm.mysql.Driver");
    15: connection = DriverManager.getConnection(connectionURL,"","");
    16: statement = connection.createStatement();
    17: rs = statement.executeQuery("SELECT * FROM books_detail");
    18: %>
    And the connectionURL parameter has this value:
    String connectionURL = "jdbc:mysql://localhost:3306/books?username=;password=";
    root cause msg is:
    java.sql.SQLException: Invalid authorization specification: Access denied for user 'nobody'@'localhost' (using password: NO)
    Please can anyone help me. It is 3 days now trying to do that but not succeded yet

    Hi
    Yes It is true that my MySQl installation its username is root. So how should put that in the url. Cause I did that but it didn.t work
    String connectionURL= "jdbc:mysql://localhost:3306/books?username=root;password=";
    If I write in that manner is it correct for root username or should I put a single quote
    Thanks

  • Syntac error in JSP and MySQL

    HI guys,
    I have been facing another problem. The codings below. Worked well with my JSP and Access database.
    Then I transfered my database to MySQL and it gives out syntax error in my SQL statement.
    CODE1:
         sql = "SELECT Week, SUM (Total_Inspected) AS ins, SUM (Total_Rejected) AS rej, SUM (Total_Accepted) AS acc, SUM (DPPM) AS dpp, SUM (Yield) AS yeel FROM Calc_Data WHERE MONTH(Inspect_Date) ="+bulann+" GROUP BY Week";
         ResultSet rs = stm.executeQuery(sql);
    CODE2:
    String query   = "SELECT ID, Model, Lot_No, Lot_Qty, Inspected_By, Reject_Desc, Area_Concerned, Location, Remark FROM OQA WHERE Customer = '"+customer+"' AND Inspect_Date =#"+tarikh+"#";
    ResultSet rs   = stmt.executeQuery(query);

    Whenever you have this type of problem, the easiest
    solution is to take the sql and try running it
    directly. For MySQL, you can either use the
    command-line client, or there are a few graphical
    clients that can handle it. Just type in the query,
    run it, and let the database itself tell you what the
    error is.
    In any case, you probably won't find much useful
    advice on a JSP forum, esp. since the problem has
    absolutely nothing to do with JSP.Indeed - I agree with this. - MOD

  • Problems with JSP and MySql bean.

    Hi,
    I'm new to JSP and I'm having some problems with it. I'm trying to do a simple login where a java class (bean?) handles the SQL injektion. I have deployed the page on tomcat and it works fine, except that the sqlinjektion does basically nothing. I have installed the mysql driver. I think there is something wrong with the java class, or the way im calling it. It does not produce any error. But its like it would never actually process the java code, because ive tried to append things to error string to see what is going on, nothing happens. everything stay null, no exceptions are thrown. If I implement the code to JSP itself, it does load the driver and print exception that there is no connection to database (which is correct). What am I missing? Code follows:
    the sqlhandler:
    public abstract class SqlInjektor {
         private static String Database = "*****";
         private static String serverName = "localhost:3306";
         private static String usrName="******";
         private static String passw="******";
         * @return Connection
         public static Connection createConnection(String error){
              Connection mySqlCon = null;
              try{
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
              catch(Exception E){
                   PrintWriter out = response.getWriter();
                   out.println("lol");
              String url = "jdbc:mysql://" + serverName + "/" + Database + "?user=" + usrName + "&password=" + passw;
              try{
                   mySqlCon = DriverManager.getConnection(url);
              catch (Exception E){
                   E.printStackTrace(System.out);
              return mySqlCon;
         * Metodi saa sy�tteen��n SQL komennon, jonka se suorittaa sek� palauttaa komennon tulokset.
         * @param command
         * @return ResultSet
         public static ResultSet querySQL(String command,String error, Connection con){
              ResultSet rs = null;
              try{
                   Statement stmt = con.createStatement();
                   rs = stmt.executeQuery(command);
              catch(Exception E){
                   E.printStackTrace(System.out);
              return rs;
    the jsp page:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page isErrorPage="false" %>
    <%@ page import="java.sql.*" %>
    <%@page import="ot3.User"%>
    <%@page import="ot3.SqlInjektor"%>
    <%@page import="Javax.servlet.jsp.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>vastaanotto</title>
    </head>
    <body>
    <%!      String id;
         String password;
         String error = new String("Error!\n");
         User user;
    %>
    <%      user = new User();
         session.putValue("currentUser",user);
         id = request.getParameter("authName");
    password = request.getParameter("Password");
         Connection conn=null;
         ResultSet rs=null;
         conn = SqlInjektor.createConnection(error);
         if(conn!=null){
              out.println("conn ok!");
              rs = SqlInjektor.querySQL("SELECT * FROM user WHERE id='" + id +"' AND password='" + password+"' COLLATE latin1_bin;",error,conn);}
         try {
              if (rs!= null && rs.next()){
                   user.setID(rs.getInt("id"));
                   user.setName(rs.getString("name"));
                   user.setPassword(rs.getString("password"));
                   user.setClearance(rs.getInt("clearance"));
                   if(rs.getString("addedby")!=null)
                        user.setAdder(rs.getInt("addedby"));
                   if(rs.getString("lastmodifier")!=null)
                        user.setModifier(rs.getInt("lastmodifier"));
                   rs.close();%>
                   ONNISTU!
              <%}
              else {
                   out.println(error);     
         } catch (SQLException e) {
              out.println(e.getMessage());
         }%>
    </body>
    </html>

    Hi,
    I'm new to JSP and I'm having some problems with it. I'm trying to do a simple login where a java class (bean?) handles the SQL injektion. I have deployed the page on tomcat and it works fine, except that the sqlinjektion does basically nothing. I have installed the mysql driver. I think there is something wrong with the java class, or the way im calling it. It does not produce any error. But its like it would never actually process the java code, because ive tried to append things to error string to see what is going on, nothing happens. everything stay null, no exceptions are thrown. If I implement the code to JSP itself, it does load the driver and print exception that there is no connection to database (which is correct). What am I missing? Code follows:
    the sqlhandler:
    public abstract class SqlInjektor {
         private static String Database = "*****";
         private static String serverName = "localhost:3306";
         private static String usrName="******";
         private static String passw="******";
         * @return Connection
         public static Connection createConnection(String error){
              Connection mySqlCon = null;
              try{
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
              catch(Exception E){
                   PrintWriter out = response.getWriter();
                   out.println("lol");
              String url = "jdbc:mysql://" + serverName + "/" + Database + "?user=" + usrName + "&password=" + passw;
              try{
                   mySqlCon = DriverManager.getConnection(url);
              catch (Exception E){
                   E.printStackTrace(System.out);
              return mySqlCon;
         * Metodi saa sy�tteen��n SQL komennon, jonka se suorittaa sek� palauttaa komennon tulokset.
         * @param command
         * @return ResultSet
         public static ResultSet querySQL(String command,String error, Connection con){
              ResultSet rs = null;
              try{
                   Statement stmt = con.createStatement();
                   rs = stmt.executeQuery(command);
              catch(Exception E){
                   E.printStackTrace(System.out);
              return rs;
    the jsp page:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page isErrorPage="false" %>
    <%@ page import="java.sql.*" %>
    <%@page import="ot3.User"%>
    <%@page import="ot3.SqlInjektor"%>
    <%@page import="Javax.servlet.jsp.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>vastaanotto</title>
    </head>
    <body>
    <%!      String id;
         String password;
         String error = new String("Error!\n");
         User user;
    %>
    <%      user = new User();
         session.putValue("currentUser",user);
         id = request.getParameter("authName");
    password = request.getParameter("Password");
         Connection conn=null;
         ResultSet rs=null;
         conn = SqlInjektor.createConnection(error);
         if(conn!=null){
              out.println("conn ok!");
              rs = SqlInjektor.querySQL("SELECT * FROM user WHERE id='" + id +"' AND password='" + password+"' COLLATE latin1_bin;",error,conn);}
         try {
              if (rs!= null && rs.next()){
                   user.setID(rs.getInt("id"));
                   user.setName(rs.getString("name"));
                   user.setPassword(rs.getString("password"));
                   user.setClearance(rs.getInt("clearance"));
                   if(rs.getString("addedby")!=null)
                        user.setAdder(rs.getInt("addedby"));
                   if(rs.getString("lastmodifier")!=null)
                        user.setModifier(rs.getInt("lastmodifier"));
                   rs.close();%>
                   ONNISTU!
              <%}
              else {
                   out.println(error);     
         } catch (SQLException e) {
              out.println(e.getMessage());
         }%>
    </body>
    </html>

  • PleaseHelp on jsp and Mysql connectivity and a lot of exception errors

    Hi,
    I am Trying to connect a JSP page with Mysql database. I am having a lot of probelms. After having a lot of problems in connecting the JSp with Mysql. Intilally it was giving me the exception error that " NO appropriate driver was found. After modifying the URl it was fine. Now It is giving the Following errors.
    servlet.ServletException: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream ** BEGIN NESTED EXCEPTION ** java.io.IOException MESSAGE: Unexpected end of input stream
    In a window before loading the Explorer page it is giving the following error that The port 8081 is already in use and i should expand to other ports. Noraml JSP Files which used to work before are also not working .
    Internal Tomcat JWSDP is alos not working. If i try to start the server it says that port 8081 is already in USe . A java.net.connection exception is also occuring. The normal JSP files are also not working. What is Happening. I am also giving the code i have writted. PLease tellme why so many exception errors are occuring.
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8081/mis_project", "root", " ");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("Select study_semester FROM Semester");
    while(rs.next()) {
    %>
    <option value="<%= rs.getString("Study_Semester") %>">
    </option>
    <% }
    if(rs!=null) rs.close();
    if(stmt!=null) stmt.close();
    if(con!=null) con.close();
    I am trying to connect to Mysql and automatocally populate a field in a Form in later JSp pages i intend to record the data entered in these fields into other tables.

    <%
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/myDB?user=username&password=mypass");
    Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
    String cat = "";
              try{
              cat = request.getParameter("category");
              }catch(NullPointerException npe){}
              ResultSet rs = stmt.executeQuery("SELECT id,fullname FROM users WHERE category LIKE '%motor%' AND subcategory like '%"+cat+"%'");
         %>
    This piece gets a category parameter from a form post and uses it to search for a specific category in a database table. I think maybe u need to download JConnector from mysql site and unzip it to the classes folder of your WEB-INF in Tomcat server...... i hope this helps a bit

  • JSP and MySQL timestamp

    hi all,
    we have a MySQL database containing a TAGLOG table and the following columns:
    TAGNUMBER, int
    TAGVALUE, float
    TAGTIMESTAMP, timestamp
    a Schneider Electric Factory Cast HMI Modicon PLC module keeps logging data from the PLC onto the TAGLOG table.
    we need to set-up a form to allow the user to select:
    start date: ____
    start time: ____
    end date: ___
    end time: ___
    so we can build a query, send to the database and when thre Result Set is received show on a table format.
    Any assistance in setting up a user friendly form to enter above dates and times will be appreciated.
    thanks in advance for any assistance.
    Trajano

    this is a problem i need to deal with soon, and am wondering the best way for it as well.
    the easiest (and quickest) would be a simple text box for each, where user types date and time as a string, with separators eg 13/03/1982 or 13:32
    Otherwise three drop-down lists, one for day, one for month & one for year. Similar for time.
    for me it's not worth creating or buying some fancy 'calendar' control, but i'm sure there are many available.

  • About jsp and mysql

    Hi all,
    Requirement:
    I have a front end in which there are 3 fields name,age,status when ever I enter values these should be stored in mysql db.and here in status I have check constraint it should be either 'Active' or 'Inactive'
    when ever I enter Active into status text field It should store as 1 in db
    when ever I enter Inactive into status text field it should store as 0 in db .
    How to acheive this please give me some suggestions
    Thanks in Advance....

    Also, rather than submit the page on clicking the 'save' button, have an onClick() attribute added to the save button that calls a javascript function. In the javascript function, do some basic client side validation before allowing the function to submit to the server. Example: name cannot be empty, age cannot be empty, age must be a number (no letters), either active or inactive must be checked.

  • JSP and MySQL

    dear all,
    I am new to sql and database programming and am a bit confussed about the line:
    Connection Conn = DriverManager.getConnection("jdbc:mysql:dbname");
    the jdbc is the what is the dbname??? is it the address of the database on your hard drive??? how is it formated??? what is the file that you need to point to??? how dies this work
    Thanks T

    Hi
    the JDBC Url should have the following format
    jdbc:mysql://<hostname>:<port>/<database>
    If your MySQL Database is running at your local host
    and it is using the default port than you can use
    jdbc:mysql://127.0.0.1:3306/test
    jdbc -> Means you are trying to open a jdbc connection
    mysql -> MySQL Databse Driver
    (make sure that your MySQL jdbc driver is registered)
    to connect to the test database on your MySQL Server
    regards
    thsimon

  • JSP and MySQL - Datetime

    Hi, I am pretty new using MySQL. I have doubt on the datetime field used in MySQL.
    Here is my issue. I have a datetime column, called CreatedDate.
    I store the strTodayDate in it.
    Date dtTodayDate = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String strTodayDate = sdf.format(dtTodayDate);
    But when I retrieve it and display on page, it gave me 2005-05-26 09:25:19.0 <--- extra dot & zero.
    Can someone please kindly advise me why?
    Thank you very much.

    When storing date time it does not realy store it in the same format you give it.
    and when you retrive the date time the my sql simply dont know in which format did you save it. So it will give it in a standerd format.
    When you store and retrive date/time value use java.sql.DateTime / Date / Time objects and always use methods like setDate and getDate. do not convert them to strings.
    I my applications I also used to store dates as long values (in millisecs) in column type BIGINT instead of actual date time column type. That way also you can overcome this problem since my sql will not treat the value as a date but as a long number.

  • Need a host free about jsp and mysql in order to test my subject project.

    Please show me a address host free . I need it to test my project. Thank so much

    Try Google Apps. Totally free.
    - Saish

  • What is the best way of deploying a jsp and bc4j aplication

    Hi
    I would like to know what is the best way of deploying a jsp and
    bc4j aplication in ias 9i.
    thanks in advanced
    rjc

    In the page I simply referenced the facescontext directly... no need for a custom servlet.
    public void createcookie() {
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletResponse resp = (HttpServletResponse)fc.getExternalContext().getResponse();
    Cookie userCookie = new Cookie("cookiename", "cookievalue");
    userCookie.setMaxAge(-1);
    userCookie.setMaxAge(3600);
    resp.addCookie(userCookie);
    return null;
    public String readcookie() {
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    Map cookiemap = ec.getRequestCookieMap();
    if (cookiemap != null) {
    Cookie cookie = (Cookie) cookiemap.get("cookievalue");
    return cookievalue;
    For reference I could not get getCookies() method of HttpServletRequest to work.. it would only return JSESSIONID.

  • An error when using JSP to activate connection between Javabean and MySQL

    I just input two paramenters in the input.htm, then click button 'submit' to
    run output.jsp, then activate adder.getSum(); This function is to add two
    number, save the sum to the MySQL database, and return the sum. I think the
    java code and jsp file are no problem. A guess it's the problem relating to
    the servlet engine trying to talk to the Javabean. Should I set some
    envirenment or other? Please take a look. If necessary, I will attach my jsp
    and java codes later.
    The error is as below:
    Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
    type Exception report
    message Internal Server Error
    description The server encountered an internal error (Internal Server Error)
    that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException:
    at org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:273)
    root cause org.apache.jasper.JasperException:
    at org.apache.jasper.runtime.JspRuntimeLibrary.convert(JspRuntimeLibrary.java:184)
    I just selected some. Thanks,

    Yes, I'd be curious to see your code. In principle that should work.
    -chicagoJava

  • Examination system using JSP/SErvlet and MySQL

    Hi
    I am new to JSP /servlet.
    I am designing online examination system using JSP/Servlet and MySQL ,where multiple choice questions would be selected randomly from the database. After completion of the examination user gets the results ,also the results would be stored in the database for the future reference.
    Can anyone guide me for this? If possible give me the code for similar type of application.
    Thanks

    Sounds like you want someone else to do your homework for you, did you not read this:
    "This forum works so much better when you try to program the code yourself, then let us know where it doesn't work. Otherwise you learn very little, and we work a whole lot."
    and this
    "If you want free code, have you tried searching Google for it? You may want to consider looking for survey software. It will give you the question/answer capabilities then all you have to do is find a way to grade the survey (if you will)...
    If you are using Tomcat as your server, which you probably are, there is a jdbc tutorial included in the documentation, that is the fastest way to set up your database.
    As for your random selection, have a look at Math.random(), this is one way to generate random numbers, you will need an algorithm to convert this value (between 0.0 and 1.0) into a form that can be used to select information from your database.

  • JSP with MYSQL on linux and windows2k

    I am using a linux box as a web server with tomcat and mysql. I aslo have a mirror on a Win2k machine running the same environment.
    I have a jsp file that uses a bean to update the database and it works on the win2k environment but not linux.
    In windows I see error messages in the tomcat console, how do I see these message on linux?
    Thank you,
    Paul.

    Did you check ALL of the files?
    There are files named "localhost_log.TODAYSDATE.txt", there are files named "catalina_log.TODAYSDATE.txt", and there's a file called "catalina.out".
    "catalina.out" appears to contain information very similar to the DOS output screen on the Windows platform.
    If those files don't have what you're looking for, then you'll have to get help from someone with more expertise than myself!

Maybe you are looking for

  • System did not find a valid bill of material

    Hi All, I have a requirement in which the client needs to supress the standard SAP message(information) which appears at the time of creation/change of sales order. Message :The system did not find valid bill of material. I am working on user exit :

  • Can GG work in a RAC environment which has no shared storage except ASM

    Gurus: I have a 2 nodes RAC which is on ASM for database data and FRA. However, it has no other shared space on the file systems. Can I still use GoldenGate? How can I do it. Please advise. dz

  • CS4 Encoder can't find source file

    Hello - I recently deleted a number of temporary files on my C: drive in order to free up space.  I then tried to export from CS4 to Encoder and it now says that it can't find the source file.  I have tried sending the exported file to a number of lo

  • Mac Exe File Graphic Freezes

    This is an odd problem. Most of the time I work with Windows projects and don't have significant problems, but I have tried to publish my projects for demonstration purposes on my MAC Powerbook, and when I have attempted this it runs fine for about 1

  • Can't open up a site in Safari - Get "Not Connected to Internet" message.

    Hello! Somehow, since this morning, my Safari stopped working. When I try to launch any website via Safari, I get a message that the computer is not connected to internet. However, it is connected and I can connect okay via Chrome. Please help! Thank