JSP, Database Retrieval

Hi
I am new to JSP and I am also using MySql for the first time. I have created my database and also created a piechart in an application format. But what I really need to know is, is it possible to bring back database values in some sort of statistical form and how?(piechart maybe)
Any help is much appreciated
Thanks

Thanks for the information but I need something more clearer. This is a college project with a deadline and if this does,not work in a weeks time, it means a direct fail, which leads to repeating the year! Any other info - help!!!!!

Similar Messages

  • Can i use Custom Tags for Database retrieval (as per MVC pattern)?

    In our project we are dealing with database, and i've used the Cutom Tags for database retrieval (as per the Article from Mr Faisal Khan) and it is working fine. But i have a doubt if it affects the performance in any way . I wanted to know if its recommendable to use Custom Tags for the DB retrieval as per MVC Pattern or shall i create a intermediate bean and then call the bean in custom tag.
    Thanks
    Prakash

    Putting database code in your JSPs certainly couples your view to the database. That's usually not good.
    If it's a simple app, it might be justified.
    When you start having lots of pages and complex business logic it becomes less attractive. - MOD

  • JSP: Data retrieval from database

    Hi Everyone...
    I know that inorder to extract a value from a database and output to the screen the syntax will be
    <%= rst.getString("DeliveryID")%>.
    But what if I want to extract the value from the database and instead of outputting to the screen, I want to assign it to a variable I have declared.
    I tried the following but it did not work:
    <% String name = request.getString("DeliveryID"); %>.
    I hope someone can help me out in this.
    regards
    BabyJava

    Hi Guys...
    Really thanks for the advice, I guess you guys are right. But it's too late for me to change anything now so I am more or less stuck with the existing design. I have got one new problem though.
    I want to update all values of a table at once and this is the SQL statement I used, but it's not working. I guess the problem could be with the way I am using the wildcard. Here is the code:
    String query = " UPDATE Customer SET CustomerID = '"+CustID +"'," +
                           " CustomerName = '"+CustName+"', CustomerPassword = '"+CustPassword+"', " +
                           " CustomerType = '"+CustType+"' , CustomerAddress = '"+CustAddress+"' ," +
                           " CustomerHandphone = '"+CustHandphone+"'" +
                           " WHERE CustomerID LIKE 'C%' ";
                           I am getting a general error. Is there anything wrong with my code??
    regards
    BabyJava

  • JSP database access application code

    Does anyone know of existing sample code, that can be downloaded, for the above that can do the following:
    1. User login
    2. Data retrieval from database
    3. Data submission by fill in form
    Any help appreciated?
    Rupert

    Here's an ad-hoc example:
    <%
    final String PREPARED_STATEMENT = "SELECT * FROM userTable WHERE userid = ? AND userpwd = ?";
    String name = "", pwd = "", errorMsg = "",
    loginsubmitted = request.getParameter("loginsubmitted"),
    intendedPath = request.getParameter("intendedPath");
    //If the intendedPath was never set then set it to your 1st protected page...
    if(null == intendedPath)
       intendedPath = "your/protected/Page.jsp";
    if(null != loginsubmitted && "true".equals(loginsubmitted))
       name = request.getParameter("name");
       pwd = request.getParameter("pwd");
       //Code to be abstracted into a servlet of some sort...
       java.sql.Connection con = dataSource.getConnection(); //Assume dataSource has been initialized elsewhere
       java.sql.PreparedStatement stmnt = con.prepareStatement(PREPARE_STATEMENT);
       stmnt.setString(1,name);
       stmnt.setString(2,pwd);
       java.sql.ResultSet rs = stmnt.executeQuery();
       rs.next();
       if(rs.isAfterLast())
          errorMsg = "Invalid user ID or password.";
       else
          request.getRequestDispatcher(intendedPath).forward(request,respone);
    %>
    <h1>Login</h1>
    <form name="login" action="thispage.jsp" method="POST">
       Name: <input type="text" name="name" value="<%=name%>"/>
       Password: <input type="password" name="pwd" value="<%=pwd%>"/>
       <input type="hidden" name="loginsubmitted" value="true"/>
       <input type="hidden" name="intendedPath" value="<%=intendedPath%>"/>
       <input type="submit"/>
       <hr/>
       <h3><%=errorMsg%></h3>
    </form>Cliff

  • Display image in jsp by retrieving it from DB2

    I insert image in to db2 table using the code given below
    PreparedStatement preparedStatement =
    connection.prepareStatement("INSERT INTO BOOKCOVERS VALUES(?,?)");
    File imageFile = new File("c:\\redbookcover.jpg");
    InputStream inputStream = new FileInputStream(imageFile);
    preparedStatement.setString(1," 0738425826");
    preparedStatement.setBinaryStream(2,inputStream,(int)(imageFile.length()));
    preparedStatement.executeUpdate();
    Now i need to retrieve the image and display in jsp page!!

    One way would be to write a Servlet... http://yourpage/ImageServlet/?id=0738425826
    Servlet:
    - get url parameter id
    - get the inputstream of the object from the db
    - read and directly write the data to the servletoutputstream
    regards
    slowfly

  • Jsp-database connectivity problem

    hi
    There is a problem, when ever i write a jdbc code for database connectivity through MsAcess, in general applications it works fine. But when ever i try to the same using Jsps it throws an exception that " Microsoft jdbc-odbc driver not fount, Default driver not specified"
    please do help regarding this
    the code i used is
    package Products; import java.sql.*;import java.util.*; public class product{          public Vector getCategories()     {          Connection con;          Statement st;          ResultSet rs;          Vector ret=new Vector(1,1);          try          {               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");               con=DriverManager.getConnection("jdbc:odbc:Web");               st=con.createStatement();               rs=st.executeQuery("Select * from Categories");               while(rs.next())               {                         ret.add(rs.getString(2));                    );               }          }          catch(Exception e)          {               //System.out.println("Exception...");               ret.add(e.getMessage());          }          return ret;     }}

    Have you downloaded the driver and put it in your Web-Server?
    In tomcat you simply need to copy the file in:
    Tomcat 5.0\common\lib

  • Database retrieving records based on time stamp

    Hello all,
                           I just  want to know that SQL query to retrieve specific time stamp record from the database using SQL server will work when same query is executed using SQL execute query.vi in labview.
                          Its not working actually.
    My query is,
    SELECT * FROM table name where col_name between 'date/time 2012-12-13 10:48:00' and 'date/time 2012-12-13 10:55:00'
    I am using mdb file. This date/time 2012-12-13 10:48:00 is first time stamp to be searched.. This is string comes from DB Tools format datetime string.vi 
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet

    A MS-Access query of a datetime field needs to be delimited wth the # (number sign / hash mark)
    Something like:
    SELECT * FROM table name where col_name between #2012-12-13 10:48:00# and #2012-12-13 10:55:00#
    I've never used the between condition; I don't know if it will work reliably with Access. I would normally use  >= and <= comparisons
    Important: the # is specific to Access. We converted from Access to SQL Server in the last year and had to find all the places that used the "#' in our LabVIEW code and replace with a single quote.
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • Reconstructing a string from a database retrieval

    What is the correct way to retrieve data such as a string from a database? If I inputing data to the database like this...
    std::string inputString = "hello world";
    data.data = &inputString;
    data.size = inputString.size();
    ret = dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE);
    and retrieving it like this...
    ret = dbp->get(dbp, NULL, &key, &data, 0);
    what do I need to do with 'data' to recover my string?
    std::string outputString = ??????;
    Thanks in advance.

    I'm using c++, just didn't realize that there was a db_cxx.h. I still have the same problem though. Here is my test code...
    #include <sys/types.h>
    #include <stdio.h>
    #include <string.h>
    #include <db_cxx.h>
    #define DATABASE "access.db"
    int main()
         Db db(NULL,0);
         int ret;
         db.open(NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0);
         std::string KEY = "THE KEY";
         std::string DATA = "THE DATA: A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
         Dbt key(&KEY, KEY.length());
         Dbt dataIn(&DATA, DATA.length());
         if((ret = db.put(NULL, &key, &dataIn, DB_NOOVERWRITE)) != 0)
              db.err(ret, "DB->put");
         Dbt dataOut;
         if((ret = db.get(NULL, &key, &dataOut, 0)) != 0)
              db.err(ret, "DB->get");
         std::string outStr = *(std::string *)dataOut.get_data();
         std::cout << outStr.c_str() << std::endl;
         if((ret = db.close(0)) != 0)
              db.err(ret, "DB->close");
         return 0;
    If I run this twice, the first time through everything behaves as I believe it should. The database gets created and the output is "THE DATA: A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z". However, the second time I run it, 'put' returns an error due to an existing identical key/data pair (as it should), but the string is just junk as if the pointer is not pointing to the correct memory location. Since 'put' returned the appropriate error message, I expect that the database is fine, and the problem is somewhere in the 'get' function or conversion back to a string. Any ideas?

  • Jsp database access using odbc - please help

    Hi friends,
    I�m trying a very simple database access program in jsp data base access using odbc. Odbc has to be used because thin driver or other drivers may not be available in every system of our college and as you know it's not that easy to make changes to those systems. My problem is so simple. I always get an exception in my program.
    My jsp content is as simple as:
    <%@ page import="java.lang.*,java.sql.*,java.io.*,registerbean" %>
    <jsp:useBean id="db" class="registerbean" scope="session"/>
    <%
    String str="insert into reg values('" + db.getName() + "','" + db.getUname() + "','" + db.getPass() + "'," + db.getAge() + ",'" + db.getSex() + "','" + db.getAdd() + "','" + db.getUgcourse() + "','" + db.getUgqual() + "'," + db.getPer() + ",'" + db.getIadd() + "')";
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:yogaesh","scott","tiger");
    Statement stmt=con.createStatement();
    stmt.executeUpdate(str);
    }catch(Exception e1){out.println(str);};
    %>
    the table reg has the structure:
    Name Null? Type
    CNAME VARCHAR2(20)
    UNAME VARCHAR2(20)
    CPSWD VARCHAR2(20)
    CONFPASS VARCHAR2(20)
    CAGE NUMBER
    CSEX VARCHAR2(5)
    CADD VARCHAR2(100)
    COURSE NUMBER
    CQUAL VARCHAR2(10)
    CPER NUMBER
    IADD VARCHAR2(100)
    The registerbean.java file is as below: (This seems to work fine because I tried printing the values using <%= %> tag and it worked out fine and moreover the query string is intact.)
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class registerbean
    private String name,uname,pass,cpass,age,sex,add,ugcourse,ugqual,per,iadd,otherugqual,ccode;
    public void setName(String a)
    name=a;
    public void setUname(String a)
    uname=a;
    public void setPass(String a)
    pass=a;
    public void setCpass(String a)
    cpass=a;
    public void setAge(String a)
    age=a;
    public void setSex(String a)
    sex=a;
    public void setAdd(String a)
    add=a;
    public void setOtherugqual(String a)
    otherugqual=a;
    public void setCcode(String a)
    ccode=a;
    public void setUgcourse(String a)
    ugcourse=a;
    public void setUgqual(String a)
    ugqual=a;
    public void setPer(String a)
    per=a;
    public void setIadd(String a)
    iadd=a;
    public String getName()
    return(name);
    public String getUname()
    return(uname);
    public String getPass()
    return(pass);
    public String getCpass()
    return(cpass);
    public String getAge()
    return(age);
    public String getCcode()
    return(ccode);
    public String getSex()
    return(sex);
    public String getAdd()
    return(add);
    public String getUgcourse()
    return(ugcourse);
    public String getUgqual()
    return(ugqual);
    public String getPer()
    return(per);
    public String getIadd()
    return(iadd);
    public String getOtherugqual()
    return(otherugqual);
    I initially thought the problem was with str but then str seems to be perfect and I get a string of the form �insert into reg values('c','c','c',98,'Male','c','B.Tech, Applied Artificial Neural Networks','HSC',9898,'h')� which I verified through a javascript debugger. The session scope used is to get values through the db bean from another jsp file. The problem is in the executeUpdate() line of this code. I even tried changing the updation table, but in vain. What could be done to rectify this? Please help me out and please do remember that I have no option but to use odbc.
    Thanks in advance.
    R. Yogaesh.

    I didn't verify the type of exception and i'm now going to do that, but then when the string is as perfect as needed, what is the need for a prepared statement? What is the basic difference between the two? And basically what is the problem with this piece of code which creates an exception? Please reply as soon as possible.
    Thankyou very much.
    R. Yogaesh.

  • JSP Database Access : 500 Internal Server Error

    Hello everybody!
    My JSP code run until I write the next:
    Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection connDB = DriverManager.getConnection("jdbc:odbc:OracleDB", "carlos_prb", "carlos_prb");
    Statement smentDB = connDB.createStatement();
    ResultSet rsDB = smentDB.executeQuery("SELECT * FROM websites");
    rsDB.close();
    smentDB.close();
    connDB.close();
    I need to access an Oracle Database. This code run in a java class, but not here. If I try to display the portlet the next message appears:
    Error: The listener returned the following Message: 500 Internal Server Error
    Somebody can help me, please?
    null

    Hi Charles,
    Thank you for yout help. I tried change this jar file for old one from
    jdeveloper 9 RC, but problem is still the same.
    I reviewed bcj4html.jar file too, and I did not discover problems in RequestParameters class.
    Have you any idea how to solve it ? I am sure that in project properties "libraries" I have selected
    all possible BC4J classes. (installation of DS and 9i database has made week before on new XP)
    Thank you very much for more info :)
    Ivo

  • JSP Database access - Urgent

    Hi,
    A simple data access program to set values in a db. I have the following problems.
    1. When I dont use if(request.getParameter("name")!=null) or any other parameter for testing null values, a row of null values is inserted each time I enter the jsp file.
    2. One more problem is that the update is not regular. It sometimes works fine, someother times it fails miserably. It seems that the connection is not closed properly as I receive such a message when I try to shut dwon oracle.
    3. A much more peculiar problem, when i paste a url directly into my browser, it runs fine, but not with location.href or a flash link!! eg the register.jsp file is reported as a nonexisting file (HTTP 404) when I provide a link to it from flash in the form http://localhost:8080/reg/register.jsp but when i type this url directly it works fine.
    My code for register.jsp is:
    <%@ page import="java.io.*,java.lang.*,java.sql.*,java.util.*"%>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:yogaesh","scott","tiger");
    Statement stmt=con.createStatement();
    if(request.getParameter("name")!=null)
    String str="insert into rt values('" + request.getParameter("name") + "','" + request.getParameter("uname") + "','" + request.getParameter("pass") + "','" + request.getParameter("cpass") + "'," + request.getParameter("age") + ",'" + request.getParameter("sex") + "','" + request.getParameter("add") + "'," + request.getParameter("code") + ",'" + request.getParameter("ugqual") + "'," + request.getParameter("per") + ",'" + request.getParameter("iadd") +"')";
    stmt.executeUpdate(str);
    stmt.close();
    con.commit();
    con.close();
    con=null;
    str=null;
    }catch(Exception e){out.println("Database error!!");}
    %>
    Please help me out and thanks in advance...
    R. Yogaesh.

    Hi,
    A simple data access program to set values in a db. I
    have the following problems.
    1. When I dont use
    if(request.getParameter("name")!=null) or any other
    parameter for testing null values, a row of null
    values is inserted each time I enter the jsp file. *********
    * Yup. Use .equals("") or .equals("null") as tests, depends on your servlet container
    2. One more problem is that the update is not regular.
    It sometimes works fine, someother times it fails
    miserably. It seems that the connection is not closed
    properly as I receive such a message when I try to
    shut dwon oracle. *************************
    Use this:
    Connection conn = null;
    try{
       //Do database stuff
    } catch {
       // Report your errors
    } finally{
       try{
         if(conn!= null){
            conn.close();
         }catch{}
    3. A much more peculiar problem, when i paste a url
    directly into my browser, it runs fine, but not with
    location.href or a flash link!! eg the register.jsp
    file is reported as a nonexisting file (HTTP 404) when
    I provide a link to it from flash in the form
    http://localhost:8080/reg/register.jsp but when i type
    this url directly it works fine.***********************
    Maybe your flash is on another computer/server? Try using the link http://<ip address>:8080/reg/register.jsp or http://<dns name>:8080/reg/register.jsp
    My code for register.jsp is:
    <%@ page
    import="java.io.*,java.lang.*,java.sql.*,java.util.*"%>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection
    con=DriverManager.getConnection("jdbc:odbc:yogaesh","sc
    tt","tiger");
    Statement stmt=con.createStatement();
    if(request.getParameter("name")!=null)
    String str="insert into rt values('" +
    request.getParameter("name") + "','" +
    request.getParameter("uname") + "','" +
    request.getParameter("pass") + "','" +
    request.getParameter("cpass") + "'," +
    request.getParameter("age") + ",'" +
    request.getParameter("sex") + "','" +
    request.getParameter("add") + "'," +
    request.getParameter("code") + ",'" +
    request.getParameter("ugqual") + "'," +
    request.getParameter("per") + ",'" +
    request.getParameter("iadd") +"')";
    stmt.executeUpdate(str);
    stmt.close();
    con.commit();
    con.close();
    con=null;
    str=null;
    }catch(Exception e){out.println("Database error!!");}
    %>
    Please help me out and thanks in advance...
    R. Yogaesh.

  • JSP + database problem...

    Hi, i would like to retrieve certain column from the database table and display it in a table format...
    for example,
    String colName[] = request.getParameterValues("col_header"); // this means that this string is dynamic, will change upon the user selection.
    And i would like to display the result in table form...
    <table>
    <tr><td>colName[0]</td> <td>colName[1]</td> .............</tr> // so on and so forth
    <tr><td> 1st result for colName[0] </td> <td> 1st result for colName[1] </td> .............</tr> // so on and so forth
    </table>
    Below is my coding.. but its result very messy and not in the format i want.
    String colName[] = request.getParameterValues("col_header");
    out.println("<table><tr>");
    for (int i=0; i<colName.length; i++){
    String name = colName;
    out.println("<td>"+name+"</td>");
    out.println("</tr>");
    out.println("<tr>");
    for (int i=0; i<colName.length; i++){
    String name = colName[i];
    out.println("<td>");
    while(rst.next()){
    out.println(rst.getString(name));
    out.println("</td>");
    out.println("</tr>");
    out.println("</table>");

    i found the solution.. thanks for whoever trying to help me

  • Create tabs from database retrieval result set?

    Trying to figure out how to dynamically create tabs based on a database result set....
    for example when page launches, a db connection starts, and a query is made to retrieve say, distinct colors available in a db table, and a tab page is generated for each color found... is there a way to do this?
    Thanks for any advice or assistance. Example would be big help.

    Thanks for the link, I think I'd read that before, but wasn't too sure how I could adapt it to create tabs... not sure where to find the method references to the tabset or tab components to call... any tips or examples would be useful. Thanks!

  • Jsp & database

    hi
    i have files examp.jsp & examp2.mdb (MS Access) files . i am running it in Tomcat 4.0 on IE. but i am getting erroras folls:
    javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.my code in .jsp file is
    <%@  page import="java.sql.*" %>
    <%
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    // set this to a MS Access DB you have on your machine
    String vPath = "/examp2.mdb";
    String filePath = getServletConfig().getServletContext().getRealPath(vPath);
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    database+= filePath.trim() + ";DriverID=22;}"; // add on to the end
    // now we can get the connection from the DriverManager
    Connection con = DriverManager.getConnection(database ,"","");
    Statement stmt=con.createStatement();
    ResultSet rs,rs1,rs2;
    %>
    <%
    String nm,ps;
    String query = "SELECT * from examp1";
    rs = stmt.executeQuery(query);
    while(rs.next()){
          nm=rs.getString("name");
          ps=rs.getString("password");
    %>
    <h3> <%= nm %>  <%= ps %> </h3>
    <% } %>examp1 is table name in db file.
    i am storing my both files in c:\program files\Apache tomcat 4.0\webapps\examples\jsp\ourproject folder FYI.
    please help me out.
    thanks.

    prob is solved
    i just shifted my folder to
    c:\program files\apache tomcat 4.0\webapps\ROOT
    thats it.

  • Oracle Single Sign on JSP Database Connection

    I am writing a JSP Search Screen that launches off of Oracle Portal (behind SSO). What I'm looking to do is have the JSP connect to the database as that user, and then show the information available to that user (we have this handled by a VPD). I was wondering how I could get access to the single signon RAD in order to connect to the database from within my JSP. Any help would be greatly appreciated.

    Hi Darsh,
    1. Oracle Internet Directory (OID) is Oracle LDAP storage solution (more here), Oracle Virtual Directory is Oracle solution that can read identity data (and filter it (mask it) based on policies) from Oracle/non-Oracle databases, Oracle/non-Oracle Directories and files and provide the user profiles as LDAP view (more here), There is nothing called Oracle Active Directory, you must be referring to Microsoft Active Directory.
    2. No, Oracle Single Sign On (OSSO) is a feature in iAS (its obsolete), Identity Management is wide umbrella of solutions and concepts.
    3. Oracle Access Manager is one component of Oracle Identity and Access Management suite of products.
    4. Webgate is Oracle access Manager agent that is installed on a webtier, it intercepts the web requests and collect the credentails, send them to Oracle Access Manager for security evaluation (decide what Authentication is needed, verify collect credentials, etc), webgate then enforce the Access Manager decision.
    5. Oracle EBS AccessGate is a java application that has the same use of OAM Webgate (it is OAM agent) but specific to E Business suite, EBS Access Gate is the new solution replacing OSSO agents, OAM is replacing OSSO server component, EBS and OSSO customers can use OAM server with OSSO agents, or with EBS AccessGate.
    HTH.
    Ghassan

Maybe you are looking for

  • Creating triggers in a logical standby database

    Does anyone know if its possible to create and enable a trigger in a logical standby database on a 'guarded' table? I've been able to create the trigger (as an after insert trigger) and it appears to be valid but it never seems to fire, despite inser

  • Download for Adobe Photoshop Elements 8

    Does anyone know where I can download Adobe Photoshop Elements 8? I have  the original, retail box with the certificate of authenticity on it. In  the box is the disc's case with a sticker with the serial number on it.  I'm just missing the disc and

  • TrackedMessages_Copy_BizTalkMsgBoxDb job is over running

    Hi, we have a application which is running on BizTalk server 2004 and uses SQl server 2000. It was working fine for past couple of years. From past 6 month we noticed that TrackedMessages_Copy_BizTalkMsgBoxDb job is over running and fails. It happens

  • OIM did not create AD account

    All, I am working on oracle 9102 BP17 version. we have runned flat file recon which should create OIM user account first and then AD account. But user was created fine in OIM, not in AD. Can some one explain why this happened?

  • IMAC / flash drive

    I just took over my sons IMAC and I plugged in my FLASH DRIVE but it does not appear anywhere   NOT even under Finder Preferences PLEASE HELP   FLASH DRIVE