Format a string values from database

how to retrive the string in the following manner from a table whose coulmn value contains 150 length string data
1. Each line must be no more than 70 characters long.
2. If the 70-character limit comes in the middle of a word, the line breaks before that word.
3. If a word is longer than 70 characters, the line will be be broken mid-word at multiples of 70 characters.
thanks in advance

Hi,
I think a user-defined PL/SQL function or procedure would be the best way to solve this.
If you want a pure SQL solution, you can do something like this:
WITH     got_break_1_pos        AS
     SELECT     txt
     ,     NVL ( REGEXP_SUBSTR ( SUBSTR (txt, 1, 70)
                              , '.{0,70}\W'
              , SUBSTR (txt, 1, 70)
                )          AS part_1
     FROM    table_x
,     got_part_2     AS
     SELECT     txt
     ,     part_1
     ,     NVL ( REGEXP_SUBSTR ( SUBSTR ( txt
                                                , 1 + LENGTH (part_1)
                                   , 70
                             , '.{0,70}\W'
                 , SUBSTR ( txt
                                , 1 + LENGTH (part_1)
                         , 70
                  )               AS part_2
        FROM     got_break_1_pos
SELECT     txt
,     part_1
,     part_2
,     SUBSTR (txt, 1 + LENGTH (part_1) + LENGTH (part_2))     AS part_3
FROM     got_part_2
;If txt can be broken into N parts, this approach requires N-1 sub-queries.
If you're using Oracle 11.2, you can have a recursive sub-query that can handle any number of parts.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Instead of breaking a string of up to 150 characters into parts of 70 characters or less, let's break a string of up to 20 characters into parts of 7 characters of less. It will make the sample data easier to handle, and you can easily change the colution to fit your real values.
Always say which version of Oracle you're using.

Similar Messages

  • How to get string value from database table using Visual Studio 2005?

    Hi,
    Im developing plugin in illustrator cs3 using visual studio 2005. I need to get the values eneterd in database. Im able to get the integer values. But while getting string values it is returning empty value.
    Im using the below code to get the values from database table
    bool Table::Get(char* FieldName,int& FieldValue)
        try
            _variant_t  vtValue;
            vtValue = m_Rec->Fields->GetItem(FieldName)->GetValue();
            FieldValue=vtValue.intVal;
        CATCHERRGET
        sprintf(m_ErrStr,"Success");
        return 1;
    Im using the below code to get the values.
    AIErr getProjects()
        char buf[5000];
        int i;   
        std::string  catName;
        ::CoInitialize(NULL);
        Database db;
        Table tbl;
        errno_t err;
        err = fopen(&file,"c:\\DBResult.txt","w");
        fprintf(file, "Before Connection Established\n");
        //MessageBox(NULL,CnnStr,"Connection String",0);
        if(!db.Open(g->username,g->password,CnnStr))
            db.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
        fprintf(file, "After Connection Established\n");
    if(!db.Execute("select ProjectID,ProjectName from projectsample",tbl))
            db.GetErrorErrStr(ErrStr);
            fprintf(file,"Error: %s\n",ErrStr);
        int ProjectID;
        int UserID;
        int ProjectTitle;
        char ProjectName[ProjectNameSize];
        if(!tbl.ISEOF())
            tbl.MoveFirst();
        ProjectArrCnt=0;
        for(i=0;i<128;i++)
            buf[i]='\0';
            int j=0;
        while(!tbl.ISEOF())
            if(tbl.Get("ProjectID",ProjectID))
                fprintf(file,"Project ID: %d ",ProjectID);
                ProjectInfo[ProjectArrCnt].ProjectID = ProjectID;
                sprintf(buf,"%d",ProjectID);
                //MessageBox(NULL, buf,"f ID", 0);
                j++;
            else
                tbl.GetErrorErrStr(ErrStr);
                fprintf(file,"Error: %s\n",ErrStr);
                break;
            //if(tbl.Get("ProjectTitle",ProjectName))
            if(tbl.Get("ProjectName",ProjectName))
                MessageBox(NULL,"Inside","",0);
                fprintf(file,"ProjectTitle: %s\n",ProjectName);
                //catName=CategoryName;
                ProjectInfo[ProjectArrCnt].ProjectName=ProjectName;
                //sprintf(buf,"%s",ProjectName);
                MessageBox(NULL,(LPCSTR)ProjectName,"",0);
            else
                tbl.GetErrorErrStr(ErrStr);
                fprintf(file,"Error: %s\n",ErrStr);
                break;
            ProjectArrCnt++;
            //MessageBox(NULL, "While", "WIN API Test",0);
            tbl.MoveNext();
        //MessageBox(NULL, ProjectInfo[i].ProjectName.c_str(),"f Name", 0);
        ::CoUninitialize();
        //sprintf(buf,"%s",file);
        //MessageBox(NULL,buf,"File",0);
        fprintf(file, "Connection closed\n");
        fclose(file);
        for(i=0;i<ProjectArrCnt;i++)
            sprintf(buf,"%i",ProjectInfo[i].ProjectID);
            //MessageBox(NULL,buf,"Proj ID",0);
            //MessageBox(NULL,ProjectInfo[i].ProjectName.c_str(),"Project Name",0);
        return 0;
    In the above code im geeting project D which is an integer value. But not able to get the project name.
    Please some one guide me.

    As I said in the other thread, this really isn't the place to ask questions about a database API unrelated to the Illustrator SDK. You're far more like to find people familliar with your problem on a forum that is dedicated to answering those kinds of questions instead.

  • Unable to access values from database in login page..

    Hey all,
    Friends I have a login.jsp page and I want if i enter username and password then it will be accessed from database and after verifying the details it will open main.jsp.I made a database as "abc" and created DSN as 1st_login having table 1st_login. But the problem is that I am unable to access values from database.
    So Please help me.
    Following is my code:
    <HTML>
    <body background="a.jpg">
    <marquee>
                        <CENTER><font size="5" face="times" color="#993300"><b>Welcome to the"<U><I>XYZ</I></U>" of ABC</font></b></CENTER></marquee>
              <br>
              <br>
              <br>
              <br><br>
              <br>
         <form name="login_form">
              <CENTER><font size="4" face="times new roman">
    Username          
              <input name="username" type="text" class="inputbox" alt="username" size="20"  />
              <br>
         <br>
              Password          
              <input type="password" name="pwd" class="inputbox" size="20" alt="password" />
              <br/>
              <input type="hidden" name="option" value="login" />
              <br>
              <input type="SUBMIT" name="SUBMIT" class="button" value="Submit" onClick="return check();"> </CENTER>
              </td>
         </tr>
         <tr>
              <td>
              </form>
              </table>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connection = DriverManager.getConnection("jdbc:odbc:1st_login");
    Statement statement = connection.createStatement();
    String query = "SELECT username, password FROM 1st_login WHERE username='";
    query += request.getParameter("username") + "' AND password='";
    query += request.getParameter("password") + "';";
    ResultSet resSum = statement.executeQuery(query);
    //change: you gotta move the pointer to the first row of the result set.
    resSum.next();
    if (request.getParameter("username").equalsIgnoreCase(resSum.getString("username")) && request.getParameter("password").equalsIgnoreCase(resSum.getString("password")))
    %>
    //now it must connected to next page..
    <%
    else
    %>
    <h2>You better check your username and password!</h2>
    <%
    }catch (SQLException ex ){
    System.err.println( ex);
    }catch (Exception er){
    er.printStackTrace();
    %>
    <input type="hidden" name="op2" value="login" />
         <input type="hidden" name="lang" value="english" />
         <input type="hidden" name="return" value="/" />
         <input type="hidden" name="message" value="0" />
         <br>
              <br><br>
              <br><br>
              <br><br><br><br><br>
              <font size="2" face="arial" color="#993300">
         <p align="center"> <B>ABC &copy; PQR</B>
    </BODY>
    </HTML>
    and in this code i am getting following error
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:93: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:93: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:94: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:95: cannot find symbol_
    4 errors
    C:\Project\SRS\nbproject\build-impl.xml:360: The following error occurred while executing this line:
    C:\Project\SRS\nbproject\build-impl.xml:142: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 6 seconds)

    As long as you're unable to compile Java code, please use the 'New to Java' forum. This is really trival.
    To ease writing, debugging and maintenance, I highly recommend you to write Java code in Java classes rather than JSP files. Start learning Servlets.

  • Returning sql statement instead of values from database

    hi am reading value from database but my problem is am get sql statement values instead of values in database
    my code is
    java:337)

    There is no doubt: you get what you want:
        return s_getValue;
    bye
    TPD

  • How to get string value from xml in JSF??

    In JSF How to get string value from xml, .ini and properties file. I want to get string value from xml or text to JSF

    Just use the appropriate API's for that. There are enough API's out which can read/parse/write XML, ini and properties files. E.g. JAXP or DOM4J for xml files, INI4J for ini files and Sun's own java.util.Properties for propertiesfiles.
    JSF supports properties files as message bundle and resource bundle so that you can use them for error messages and/or localization.

  • How can i get the random values from database?

    Hi,
    i want to get random values from database.
    I try my best find no solution
    plz give solution in either sql query or java method.
    thanks in advance.

    try this:
    Give a numeric row-id to each row of database.
    say (1-100) for 100 rows
    In the program use random function to get random number between 0 and 1. this value u multiply with 100(or total number of rows) and take integer value of it . u then perform sql query to select the a row which matches randomly genarated value with row-id assigned to each row of database
    madhu

  • Fetching values from database into a drop down box

    in my JSP page there are 3 drop down boxes for date of birth......
    what i need is i want to get the values from database into that drop down box when i access the JSP page.......
    session is there....'m getting all other values.......
    I will attach the JSP page.....
    Please help me...........
    Thanks in Advance......
    <%@ taglib uri='/WEB-INF/taglib/struts-bean.tld' prefix='bean'%>
    <%@ taglib uri='/WEB-INF/taglib/struts-logic.tld' prefix='logic'%>
    <%@ taglib uri='/WEB-INF/taglib/dyna.tld' prefix='dyna'%>
    <%@ taglib uri='/WEB-INF/taglib/struts-html.tld' prefix='html'%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title><bean:message key="page_title"/></title>
    <link href="<bean:message key="context"/>/CSS/default.css" rel="stylesheet" type="text/css" />
    <script src="<bean:message key="context"/>/js/AC_RunActiveContent.js" type="text/javascript"></script>
    <link href="<bean:message key="context"/>/CSS/screen.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <%!
    Membership mShip = null;
    %>
    <script language="javascript" >
    function checkDate(Form){
    var d;
    d = Form.year.value+"-"+Form.month.value+"-"+Form.day.value;
    alert("Date is:"+d);
    Form.dob.value = d;
    </script>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>
         <jsp:include flush="true" page="../templates/header.jsp"/>     </td>
    </tr>
    <tr>
    <td class="menuTD">     
         <jsp:include flush="true" page="../templates/menu.jsp"/>     </td>
    </tr>
    <tr>
    <td class="sub_menuTR"> </td>
    </tr>
    <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td class="column" valign="top" width="170"><jsp:include flush="true" page="../templates/left_panel.jsp"/></td>
    <td valign="top" align="left">
              <dyna:message error="error" warning="warning" message="message"/>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="80%" valign="top" align="left">
                   <%
                   if(session != null){
                   mShip = (Membership)session.getAttribute("member");
                   %>
                        <form action="updateContactDetails.dy" method="post" name="form1">
                        <input type="hidden" name="m" value="<%=request.getParameter("m")%>" />
                             <table width="100%" border="0">
                             <tr>
                                  <td>First Name</td>
                                  <td><input name="first_name" type="text" id= "first_name" value = "<bean:write name = "member" property = "first_name" />" /></td>
                             </tr>
                             <tr>
                                  <td>Last Name </td>
                                  <td><input name="last_name" type="text" id="last_name" value = "<bean:write name = "member" property = "last_name" />" > </td>
                             </tr>
                             <tr>
                                  <td>Address</td>
                                  <td><input name="address1" type="text" id="address1" value = "<bean:write name = "member" property = "address1" />" ></td>
                             </tr>
                             <tr>
                                  <td> </td>
                                  <td><input name="address2" type="text" id="address2" value = "<bean:write name = "member" property = "address2" />" ></td>
                             </tr>
                             <tr>
                                  <td>Suburb/City </td>
                                  <td><input name="city" type="text" id="city" value= "<bean:write name = "member" property = "city" />" ></td>
                             </tr>
                             <tr>
                                  <td>State/Territory</td>
                                  <td><input type="text" name="state" value = "<bean:write name = "member" property = "state" />" ></td>
                             </tr>
                             <tr>
                                  <td>Postcode</td>
                                  <td><input type="text" name="postcode" value = "<bean:write name = "member" property = "postcode" />" ></td>
                             </tr>
                             <tr>
                                  <td>Contact Phone</td>
                                  <td><input type="text" name="home_phone" value = "<bean:write name = "member" property = "home_phone" />" ></td>
                             </tr>
                             <tr>
                                  <td>Mobile</td>
                                  <td><input type="text" name="mobile" value = "<bean:write name = "member" property = "mobile" />" ></td>
                             </tr>
                             <tr>
                                  <td>Date of birth</td>
                                  <td nowrap="nowrap"><select name="day">
    <option>Day</option>
    <option value="01">1</option>
    <option value="02">2</option>
    <option value="03">3</option>
    <option value="04">4</option>
    <option value="05">5</option>
    <option value="06">6</option>
    <option value="07">7</option>
    <option value="08">8</option>
    <option value="09">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="14">14</option>
    <option value="15">15</option>
    <option value="16">16</option>
    <option value="17">17</option>
    <option value="18">18</option>
    <option value="19">19</option>
    <option value="20">20</option>
    <option value="21">21</option>
    <option value="22">22</option>
    <option value="23">23</option>
    <option value="24">24</option>
    <option value="25">25</option>
    <option value="26">26</option>
    <option value="27">27</option>
    <option value="28">28</option>
    <option value="29">29</option>
    <option value="30">30</option>
    <option value="31">31</option>
    </select>
                                  <select name="month">
                                       <option>Month</option>
                                       <option value="01">January</option>
                                       <option value="02">February</option>
                                       <option value="03">March</option>
                                       <option value="04">April</option>
                                       <option value="05">May</option>
                                       <option value="06">June</option>
                                       <option value="07">July</option>
                                       <option value="08">August</option>
                                       <option value="09">September</option>
                                       <option value="10">October</option>
                                       <option value="11">November</option>
                                       <option value="12">Decembber</option>
                                  </select>
                                       <select name="year" onChange = "checkDate(this.form);" >
                                       <option>Year</option>
                                       <option value="1957">1957</option>
                                       <option value="1956">1956</option>
                                       <option value="1955">1955</option>
                                       <option value="1954">1954</option>
                                       <option value="1955">1955</option>
                                       <option value="1956">1956</option>
                                       <option value="1957">1957</option>
                                       <option value="1958">1958</option>
                                       <option value="1959">1959</option>
                                       <option value="1960">1960</option>
                                       <option value="1961">1961</option>
                                       <option value="1962">1962</option>
                                       <option value="1963">1963</option>
                                       <option value="1964">1964</option>
                                       <option value="1965">1965</option>
                                       <option value="1966">1966</option>
                                       <option value="1967">1967</option>
                                       <option value="1968">1968</option>
                                       <option value="1969">1969</option>
                                       <option value="1970">1970</option>
                                       <option value="1971">1971</option>
                                       <option value="1972">1972</option>
                                       <option value="1973">1973</option>
                                       <option value="1974">1974</option>
                                       <option value="1975">1975</option>
                                       <option value="1976">1976</option>
                                       <option value="1977">1977</option>
                                       <option value="1978">1978</option>
                                       <option value="1979">1979</option>
                                       <option value="1980">1980</option>
                                       <option value="1981">1981</option>
                                       <option value="1982">1982</option>
                                       <option value="1983">1983</option>
                                       <option value="1984">1984</option>
                                       <option value="1985">1985</option>
                                       <option value="1986">1986</option>
                                       <option value="1987">1987</option>
                                       <option value="1988">1988</option>
                                       <option value="1989">1989</option>
                                       <option value="1990">1990</option>
                                       <option value="1991">1991</option>
                                       <option value="1992">1992</option>
                                       <option value="1993">1993</option>
                                       <option value="1994">1994</option>
                                       <option value="1995">1995</option>
                                       <option value="1996">1996</option>
                                       <option value="1997">1997</option>
                                       <option value="1998">1998</option>
                                       <option value="1999">1999</option>
                                       <option value="2000">2000</option>
                                       <option value="2001">2001</option>
                                       <option value="2002">2002</option>
                                       <option value="2003">2003</option>
                                       <option value="2004">2004</option>
                                       <option value="2005">2005</option>
                                       <option value="2006">2006</option>
                                       <option value="2007">2007</option>
                             </select ></td></tr>
                             <tr>
                                  <td><input type="hidden" name = "dob" /> </td>
                                  <td nowrap="nowrap"><input type="submit" value="Submit" /></td>
                             </tr>
                             </table>
                        </form>
                   </td>
    <td width="40"></td>
    <td width="200" valign="top">
                   <div id="headlines">
    <jsp:include flush="true" page="../templates/profile.jsp"/>
    </div>
                   </td>
    </tr>
    </table>
              </td>
    <td> </td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><jsp:include flush="true" page="../templates/footer.jsp"/></td>
    </tr>
    </table>
    </body>
    </html>

    i think normally u will get data from databsae as objects.they are like java beans having getter and setter methods.so you create a collection of those objects like collect all the objects coming from database into an arraylist or....
    suppose you want to populate the dropdown box with say "username" from database object s, your code will look like that
    <html:select property="name">
    <html:options collection="databaseList" property="username" />
    </html:select>
    "databaseList" is collection(say.. ArrayList) of objects you are getting from database.this dropdown will contain all the "usernames" you are getting from database.

  • List of values from Database Adapter - BPM Forms

    Hi all,
    Can anyone tell me how to get list of values from Database adapter and a ServiceTask.
    As example lets say a table has Employee and Department columns.
    I want to list down all the Employees in BPM form (Select One List Box) once i provide the department to the Database Adapter.
    Is it possible from the DB Adapter?? What will be the variable type?
    Thanks,
    Nir

    Hi DanielAtwood,
    Thanks for your reply...
    Actually when i send the variable in 'WHERE Clause' in Db Adapter query it will retrieve more than one record as the output.
    I want to put that values to a 'SelectOneChoice' component and list down all the values..
    First I tried with data control. But i couldn't find the way to pass the value to the variable(in WHERE clause) to the query in data control view.
    Thanks,
    Nir

  • How to retrieve query string value from the URL in my portlet

    Hi,
    When user clicks on "Advance Search", i am redirecting to page in the community. At the same i am adding some more values to the query string (to the URL).
    My URL will look like this.
    http://ctp-mc0149/portal/server.pt?space=CommunityPage&parentname=CommunityPage&parentid=0&in_hi_userid=200&cached=true&control=SetCommunity&PageID=202&CommunityID=200&searchType=2
    Now in one of my portlet in that page, i want to retrieve the query string values from the URL.
    Please help me regarding this.
    Thanks in advance.
    Thanks,
    sreekanth.

    Hi,
    Look at the following threads,
    For programmatically getting the iview properties,
    Programmatically getting iView Properties
    Also,
    Get Properties of IView Programmatically
    Permanent change of iView property programmatically
    Hope these threads help u.
    Regards
    Srinivasan T

  • How to popup values from database tables to SelectOneMenu

    Hi friends,
    I am doing a jsf application, in which there is a selectOneMenu
    control and I want that, iwhen this page is loaded after clicking button
    on the previous page, the selectOne Menu should be populated with
    the values from database.
    Also I want , if i will select any menu item from the menu , acccordingly
    another selectOneMenu control should be filled with respective values
    thanx,
    bye

    Oh dear. I don't think anybody can advise you until you are not "kinda" new to Java anymore. Learn Java itself (the language, the platform and the tools), only then should you start considering going into web development.

  • How to fill bean area with values from database

    i have a bean area in form which act as acombobox autocomplete , i want to fill it with dynamic values from database , any help will be appreciated.
    http://forms.pjc.bean.over-blog.com/article-16369664.html "this is the example i'm working on"
    Best Regards.

    An example with the EMP table:
    DECLARE
      cursor cur is select empno,ename from emp;
    BEGIN
      -- initialise the ComboBox twin values --
      for c in cur loop
       if c.empno is not null then
        Set_Custom_Property('BL.BEAN',1,'ADD_TWIN',c.empno||','||c.ename);
       else
        Set_Custom_Property('BL.BEAN',1,'ADD_TWIN_NULL',c.empno||','||c.ename);
       end if ;
      end loop;
      Set_Custom_Property('BL.BEAN',1,'ADD_TWIN','[END_DATA]');
      Set_Custom_Property('BL.BEAN',1,'SET_ALIGNMENT','right');
    END;Francois

  • Get string value from enumerated value on AE user interface

    Hello.
    I'm trying to get the string value from a enumerated value on a layer's property.
    When I get the value via script, I have  1D value. However, I need the string value.
    In this example, the value I would get is 1. Is there any way I can get "Horizontal and Vertical".
    I'm looking for a generic way (any property value defined this way), not for this case only.
    Thanks for the help.
    cheers.

    You get the selected value via the value property of the component.
    Timo

  • How to send a String value  from Servlet to  Action class in Struts .

    when iam trying to send string value from Servlet to Struts Action class through Http Session, iam getting null value, iam really in big confusion, help me.

    please elaborate clearly or put you code of both action and servlet here
    Are both of them in same web application

  • Have a error in getting the values from database randomly

    Hi to all
    I am new member to this community and new to java programming, i am the one of them who got benefited through this site , with that hope i am asking u to clear my doubt.
    Actually i want to get the data from database randomly, i dont have problem either in database connection and generating random number,its working fine. but when i have to get the data from database with generated random no using absolute function , i am getting an exception
    eg : rs.absolute(2);
    i could not move to the second row of my result set.
    not only absolute function whatever the function i am using except next method, getting exception.
    my code :
    package practical;
    import java.util.*;
    import java.sql.*;
    public class gen {
         Connection con;
         Statement s;
         ResultSet rs;
         public void get(int t)
              try
                   rs.absolute(t);
                   String question=rs.getString("question");
                   System.out.println("Random question : "+question);
              catch(Exception e)
                   System.out.println("get error");
         public void ran()
              Random r=new Random();
                   for(int i=0;i<10;i++)
                        int j=r.nextInt(10);
                        System.out.println("random value : "+j);
                        if(j!=0)
                             try
                                  get(j);
                             catch(Exception e)
                                  System.out.println("ran error");
         public void connect()
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   con=DriverManager.getConnection("jdbc:odbc:ds","sa","server");
                   s=con.createStatement();
                   rs=s.executeQuery("select question from qa");
                   ran();
                   con.close();
              catch(Exception e)
                   System.out.println("error");
         public static void main(String... strins)
              new gen().connect();
    }

    but i acheived through the code which is pasted below but i have to close the database connection for every iteration.
    package practical;
    import java.util.*;
    import java.sql.*;
    public class gen {
         Connection con;
         Statement s;
         ResultSet rs;
         public void get(int t)
              int c=0;
              while(c!=t)
                   try
                   rs.next();
                   c++;
                   catch(Exception e)
                        System.out.println("next error");
              if(c==t)
              {     try
                        String question=rs.getString("question");
                        System.out.println("Random question : "+question);
                   catch(Exception e)
                        System.out.println("iteration error");
         public void ran()
              Random r=new Random();
                   int j=r.nextInt(10);
                   System.out.println("random value : "+j);
                   if(j!=0)
                        try
                             get(j);
                        catch(Exception e)
                             System.out.println("ran error");
         public void connect()
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   con=DriverManager.getConnection("jdbc:odbc:ds","sa","server");
                   s=con.createStatement();
                   rs=s.executeQuery("select question from qa");
                   ran();
                   con.close();
              catch(Exception e)
                   System.out.println("error");
         public static void main(String... strins)
              for(int i=0;i<10;i++)
                   new gen().connect();
    }

  • Retrieve values from database

    Hi,
    one of the search form contains the select option for country , state and
    distributor type.
    the country drop down has 2 values - US and canada
    the conditions needed to be satisfied are :
    (1) if the country selected is US - then the states dropdown should only show the states that are associated with US in the table in the database(TABLE name is - "distributors")
    and if country selected is Canada - then should show states in canada only
    (2) if canada is selected in the country dropdown, the distributor type which has 2 values - stationary and automotive - should show only the stationary in the dropdown and not show the automotive
    This is done with the LocateQueryServlet.java...can someone please tell me how this needs to be updates so that the above conditions are satisfied...
    Attaching the code from LocateQueryServlet.java and the prolog.sql
    --------------------------------------------------------------------------------------------------LocateQueryServlet.java
    package com.dupont.refrigerants.distributorlocator;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Iterator;
    import java.util.List;
    import javax.ejb.CreateException;
    import javax.naming.NamingException;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.proxicom.util.MiscEJBFunctions;
    * This servlet displays a query form for locating distributors. It relies on
    * the 'countries', 'states' and 'types' tables in the database to fill its
    * forms. If a table is empty, it doesn't display the corresponding select
    * (pulldown) widget. This only displays the form fragment of HTML, and should
    * be included in a complete page, probably with JSP or the like.
    * XXX Currently, the form is populated when the servlet is initialized, which
    * is a hack because I don't remember the appropriate j2ee idiom.
    * @web.servlet name="queryServlet" display-name="Distributor Locator Query
    * Servlet" description="Servlet that gets a query form for finding
    * distributors in a given region"
    * @web.servlet-mapping url-pattern="/queryServlet"
    public class LocateQueryServlet extends HttpServlet {
         * Abstract class for converting a java object into
         * an option element for an HTML select form widget.
         private abstract static class Object2Option {
              * Gets the default option at the top of the select.
              * To have no default, override this to return the
              * empty string.
              * @return <code>>option selected='true' value=''<-- Select One -->/option<</code>
              public String getDefault() {
                   return "<option selected='true' value=''>-- Select One --</option>";
              * The option element that represents the given info object.
              * @param o the info object
              * @return an unselected HTML option element.
              abstract public String getOptionFor(Object o);
              * Helper method for generating a select option element
              * with the given un-encoded value and text.
              * @param value
              * unencoded string to be passed as the form
              * value when selected
              * @param text
              * unencoded string to be displayed in the select
              * box pulldown
              * @return the concatenated and appropriately escaped
              * option element
              protected static String getOptionWith(String value, String text) {
                   return "<option value='" + Utilities.webify(value, false) + "'>"
                             + Utilities.webify(text, false) + "</option>";
         * Function object for generating 'Country' select box items.
         private static class Object2CountryOption extends Object2Option {
              * Converts a CountryInformation object into an appropriate
              * HTML option element.
              public String getOptionFor(Object o) {
                   CountryInformation c = (CountryInformation) o;
                   return getOptionWith(c.getCode(), c.getName());
         * Function object for generating 'Distributor Type' select box items.
         private static class Object2DistributorTypeOption extends Object2Option {
              * Converts a DistributorTypeInformation object into an appropriate
              * HTML option element.
              public String getOptionFor(Object o) {
                   DistributorTypeInformation c = (DistributorTypeInformation) o;
                   return getOptionWith(String.valueOf(c.getId()), c.getDescription());
         * Function object for generating 'State/Province' select box items.
         private static class Object2StateOption extends Object2Option {
              * Converts a StateInformation object into an appropriate
              * HTML option element.
              public String getOptionFor(Object o) {
                   StateInformation c = (StateInformation) o;
                   return getOptionWith(c.getCode(), c.getName());
         private String countries;
         private String states;
         private String types;
         * Constructs a simple locate query servlet.
         public LocateQueryServlet() {
              super();
         * Generates an HTML select form widget for the given list of values.
         * @param formName the name of the widget for the HTML name attribute
         * @param values the values to convert into a list
         * @param factory the method for converting each value into an option.
         * @return the complete 'select' element
         private String generateSelectFor(String formName, List values,
                   Object2Option factory) {
              StringBuffer sb = new StringBuffer();
              sb.append("<select name='").append(Utilities.webify(formName, false)).append("'>");
              sb.append(factory.getDefault());
              for (Iterator iter = values.iterator(); iter.hasNext();) {
                   sb.append(factory.getOptionFor(iter.next()));
              sb.append("</select>");
              return sb.toString();
         * Initializes the servlet. Actually results in some queries getting run.
         * @param config
         * @throws ServletException
         public void init(ServletConfig config) throws ServletException {
              try {
                   DistributorDBABeanHome distBean = (DistributorDBABeanHome) MiscEJBFunctions.getBeanHomeInterface(null, null, Utilities.EJB_DISTRIBUTOR_DBA_NAME);
                   DistributorDBABean dists = distBean.create();
                   this.countries = this.generateSelectFor("country", dists.getCountries(),
                             new Object2CountryOption());
                   this.states = this.generateSelectFor("state", dists.getStates(),
                             new Object2StateOption());
                   this.types = this.generateSelectFor("type", dists.getDistributorTypes(),
                             new Object2DistributorTypeOption());
              } catch (NamingException e) {
                   throw new ServletException("Lookup of "
                             + Utilities.EJB_DISTRIBUTOR_DBA_NAME + " failed", e);
              } catch (CreateException e) {
                   throw new ServletException(
                             "Error while creating distributor session bean", e);
              } catch (java.rmi.RemoteException e) {
                   throw new ServletException(
                             "Error while initializing distributor locator", e);
         * Executes the HTTP request and return the appropriate HTML form fragment.
         * @param request
         * @param response
         * @throws ServletException
         * @throws IOException
         protected void doGet(HttpServletRequest request,
                   HttpServletResponse response) throws ServletException, IOException {
              PrintWriter out = response.getWriter();
              response.setContentType("text/html");
              String action = request.getParameter("action");
              if (action == null) {
                   action = "where-to-buy-results";
              } else {
                   action = Utilities.webify(action, false);
              // Open form and table elements.
              out.println("<form id='distributorLocator' action='" + action + "' method='get'>"
                                  + "<table width='100%' border='0' cellpadding='4' cellspacing='0'>");
              // buffer row
              //out.println("<tr><td colspan='2'><hr width='65%' size='1' noshade></td></tr>");
              // 'Country' row
              out.println("<tr><td><div align='right' class='formSubHead'>Country:</div></td>"
                                  + "<td>" + this.countries + "</td></tr>");
              // 'States' row
              out.println("<tr><td><div align='right' class='formSubHead'>State/Province:</div></td>"
                                  + "<td>" + this.states + "</td></tr>");
              // 'Application' row
              out.println("<tr><td><div align='right' class='formSubHead'>Application:</div></td>");
              out.println("<td>" + this.types + "</td></tr>");
              // or row
              out.println("<tr><td><div align='right'></div></td><td><em><strong>or</strong></em></td></tr>");
              // zip code row
              out.println("<tr><td><div align='right' class='formSubHead'>Zip Code/Postal Code: </div></td>"
                                  + "<td><input id='zip' name='zip' type='text' /></td></tr>");
              // buffer row
              out.println("<tr><td colspan='2'><hr width='65%' size='1' noshade></td></tr>");
              // submit row
              out.println("<tr><td> </td><td><input type='submit' value='Find' /></td></tr>");
              // end table and form
              out.println("</table></form>");
    prolog.sql
    SET DEFINE OFF;
    CREATE SEQUENCE distributor_id_seq START WITH 1 INCREMENT BY 1 NOMAXVALUE;
    CREATE TABLE countries (code CHAR(2), name VARCHAR(254),
         CONSTRAINT country_pk PRIMARY KEY(code));
    CREATE TABLE states (code CHAR(5), name VARCHAR(254), country CHAR(2),
         CONSTRAINT state_pk PRIMARY KEY(code),
         CONSTRAINT fk_country FOREIGN KEY(country) REFERENCES countries(code));
    CREATE TABLE distributorTypes (id INTEGER, name VARCHAR(254),
         CONSTRAINT distributorType_pk PRIMARY KEY(id));
    CREATE TABLE distributors
         (id INTEGER,
         name VARCHAR(254),
         zip VARCHAR(12),
         country CHAR(2),
         state CHAR(5),
         city VARCHAR(63),
         address1 VARCHAR(254),
         address2 VARCHAR(254),
         fax VARCHAR(32),
         phone VARCHAR(32),
         managers VARCHAR(254),
         type INTEGER,
         email VARCHAR(254),
         url VARCHAR(254),
         CONSTRAINT distributor_pk PRIMARY KEY(id),
         CONSTRAINT fk_dist_country FOREIGN KEY(country) REFERENCES countries(code),
         CONSTRAINT fk_dist_state FOREIGN KEY(state) REFERENCES states(code),
         CONSTRAINT fk_dist_type FOREIGN KEY(type) REFERENCES distributorTypes(id));
    CREATE TABLE statesApply (state CHAR(5), distributor INTEGER,
         CONSTRAINT fk_apply_state FOREIGN KEY(state) REFERENCES states(code),
         CONSTRAINT fk_apply_distributor FOREIGN KEY(distributor) REFERENCES distributors(id));
    INSERT INTO
              distributorTypes (id, name) VALUES (1, 'Air Conditioning - Stationary and Refrigeration');
    INSERT INTO
              distributorTypes (id, name) VALUES (2, 'Air Conditioning - Automotive');
    INSERT INTO
              countries (code, name) VALUES ('CA', 'Canada');
    INSERT INTO
              countries (code, name) VALUES ('US', 'United States of America');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_AL', 'Alabama');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_KS', 'Kansas');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_ND', 'North Dakota');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_AK', 'Alaska');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_KY', 'Kentucky');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MP', 'N. Mariana Islands');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_AS', 'American Samoa');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_LA', 'Louisiana');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_OH', 'Ohio');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_AZ', 'Arizona');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_ME', 'Maine');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_OK', 'Oklahoma');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_AR', 'Arkansas');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MH', 'Marshall Islands');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_OR', 'Oregon');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_CA', 'California');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MD', 'Maryland');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_PW', 'Palau');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_CO', 'Colorado');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MA', 'Massachusetts');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_PA', 'Pennsylvania');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_CT', 'Connecticut');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MI', 'Michigan');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_PR', 'Puerto Rico');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_DE', 'Deleware');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MN', 'Minnesota');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_RI', 'Rhode Island');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_DC', 'District of Columbia');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MS', 'Mississippi');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_SC', 'South Carolina');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_FM', 'FS Micronesia');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MO', 'Missouri');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_SD', 'South Dakota');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_FL', 'Florida');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_MT', 'Montana');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_TN', 'Tennessee');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_GA', 'Georgia');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NE', 'Nebraska');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_TX', 'Texas');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_GU', 'Guam');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NV', 'Nevada');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_UT', 'Utah');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_HI', 'Hawaii');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NH', 'New Hampshire');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_VT', 'Vermont');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_ID', 'Idaho');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NJ', 'New Jersey');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_VI', 'Virgin Islands');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_IL', 'Illinois');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NM', 'New Mexico');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_VA', 'Virginia');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_IN', 'Indiana');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NY', 'New York');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_WA', 'Washington');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_IA', 'Iowa');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_NC', 'North Carolina');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_WV', 'West Virginia');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_WI', 'Wisconsin');
    INSERT INTO
              states (country, code, name) VALUES ('US', 'US_WY', 'Wyoming');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_AB', 'Alberta');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_BC', 'British Columbia');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_MB', 'Manitoba');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_NB', 'New Brunswick');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_NL', 'Newfoundland and Labrador');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_NS', 'Nova Scotia');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_NT', 'Northwest Territories');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_NU', 'Nunavut');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_ON', 'Ontario');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_PE', 'Prince Edward Island');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_QC', 'Qu�bec');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_SK', 'Saskatchewan');
    INSERT INTO
              states (country, code, name) VALUES ('CA', 'CA_YT', 'Yukon');
    Any immediate help is truly appreciated.
    Thanks in advance

    I thank you for the link, it's something I've already done several times ....
    actually this code tries to manage a key incremental, I am obliged to do that because I am in MS SQL Server and therefore what works for oracle does not work for SQL Server, which is why I want to do it manual, I also posted this in a previous post and I was asked to retrieve the field value by Code: Help please : dbsequence refresh on MS sql server
    now admitting that it is not what I want to do and I have the following code:
    if (it1.getValue () == null) (
    Connection connection = ConnectionManager.getInstance (). GetConnection ();
    Statement statement = connection.createStatement ();
    ResultSet resultset = statement.executeQuery ("SELECT id FROM WHERE name = spider" it2.getValue + () + "");
    while (resultSet.next ())
    it1.setValue (resultSet.getInt (1));
    BindingContainer getBindings bindings = ();
    OperationBinding operationBinding bindings.getOperationBinding = ("Commit");
    OperationBinding.execute Object result = ();
    if (! operationBinding.getErrors (). isEmpty ()) (
    return null;
    else (
    BindingContainer bindings2 getBindings = ();
    OperationBinding operationBinding2 bindings2.getOperationBinding = ("Commit");
    OperationBinding2.execute Object result = ();
    if (! operationBinding2.getErrors (). isEmpty ()) (
    return null;
    What code ADF BC I will put in place of jdbc code

Maybe you are looking for

  • Why can't I drop a call on three way calling

    Ok so someo called me and then I call someone else but the person didn't answer but when I tried to hang up it hung up on both parties it didn't give me an option to add another call or hang up on the person I was calling

  • Display Column Value Once

    Hey, I am trying to only display a column value one time for a record, not a static value. The value changes and there can be many values. I do not think grouping will work since the Date value is dynamic. I am using Oracle for Toad 10.5. There are 4

  • SCW in SAP Security

    Hi Experts, In SAP Security we have a tool called SCW. In security we have tables for example AGR_1252, in this table we organize elements for authorization.Some fields will be updated. Now, we are importing this data into an excel sheet and we are e

  • Losing sync while exporting

    I have a series of 1-2 minute clips I'm having trouble exporting. They were shot, captured, and edited on HDV. When I go to export them using Quicktime conversion, the audio plays fine but the video will frequently skip. It goes in and out of sync se

  • Enumeration for ExportType

    Where can I find the numeric value of the attribute ExportType.SAVEFORWEB? By way of explanation, I'm trying to script Photoshop's Save for Web and Devices with Python. I'm using the win32com.client, which won't accept named attributes like ExportTyp