Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Readiing in Db table and putting data into javascript select.

Posted on 2003-10-22
14
175 Views
Last Modified: 2010-04-01
I need to hit a db and read in the contents of a specific table and put it (multiple data) in a select for that page. Any help appreciate!
0
Comment
Question by:894359
  • 4
  • 4
  • 2
  • +2
14 Comments
 
LVL 3

Accepted Solution

by:
applekanna earned 500 total points
ID: 9600226
In a JSP , For a table from an access db to be dispayed within <td></td> in ur html
My DSN is sample


<td> My Database Select
<!--connecting to database -->
                        <%@ page import="java.sql.*, java.io.*, java.util.*" %>
                        <%
                             try{
                                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                 }
                            catch(Exception e){
                                                 }


                                  Connection connect=DriverManager.getConnection("jdbc:odbc:sample");
                                  Statement stmt=connect.createStatement();
                                  ResultSet result=stmt.executeQuery("select * from testTable"); %>


                       <select name="test">
                          <option value=" "></option>
                        <%
                          String temp = " ";
                          while(result.next())
                          { %>
                            <option >
                            <%
                              temp=result.getString(1); //The value
                                                         %>
                            <%= temp %> </option>
                      <%  }
                        result.close();
                        connect.close(); %>
                        </select>
    </td>
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9600229
what db are u using..

does this help ?

.. Cheers!
0
 

Author Comment

by:894359
ID: 9601177
Oracle 11i.. I will try it! I think it does help???
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:applekanna
ID: 9601413
DO tell me if u need more help
Cheers!
0
 

Author Comment

by:894359
ID: 9601869
I will... thank you! :)
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 9603613
I did read data from Oracle, the connection pool i used is customized from DbConnectionBroker from http://www.javaexchange.com/ , you can go and taka a look on its examples.

Find more examples at:

jspin.com and jspinsider.com

Hope this helps

0
 

Expert Comment

by:TGV
ID: 9605199
putting data into javascript select?
What do you mean by it
0
 

Author Comment

by:894359
ID: 9608785
I need to dynamically populate a select based on the previous form and the selections made on that form. So if for example some body picked USA as their country on form 1 on the next form (form2) I'm going to know that and load associated vendors (from db) for that country in to a select.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9609129
Did the previous posts solve your problem

Cheers!
0
 

Author Comment

by:894359
ID: 9609233
I haven't been able to try it yet due to major server problems! :( I'm still waiting!!!
0
 
LVL 2

Expert Comment

by:Karaa
ID: 9616954
try it
<%
String countr;
if (countr==null)
      countr="";  
%>

<select name="country" size="1" id="<%=countr%>" style="width:140px;"tabindex="15">
            <option value="null" <%=(("null".toString().equals(countr))?"SELECTED":"")%>></option>
            <option value="1" <%=(("1".toString().equals(countr))?"SELECTED":"")%>>Belgium</option>
            <option value="2" <%=(("2".toString().equals(countr))?"SELECTED":"")%>>France</option>
            <option value="3" <%=(("3".toString().equals(countr))?"SELECTED":"")%>>United
            Kingdom</option>
onSubmit
      session.setAttribute("countr", countr);


in next page
countr=(String) session.getAttribute("countr");
use it in your sql query to get your resultset
hope you'll get it
Good luck
0
 
LVL 2

Expert Comment

by:Karaa
ID: 9617007
to put in a select box?
<%
            conn = null;
            stmt = null;
            rset = null;
            
            connStr="jdbc:oracle:thin:@localhost:1521:db_name";
//depends which connexion u r using
            conn = DriverManager.getConnection(connStr,
                                                         "Scott", "tiger");
            stmt = conn.createStatement ();
            str = "SELECT CLIN_ID,CLIN_NAME FROM F_CLINIC where COUNTR_ID="+countr+" order by CLIN_NAME";
            rset = stmt.executeQuery(str);
%>
          <select name="clinics_list" id="<%=clin%>"style="width:140px;" tabindex="14">
            <%
    while (rset.next())
    {
        String  clin_id = rset.getString(1);
        String  clin_name = rset.getString(2);
%>
            <option value="<%=clin_id%>" <%=((clin_id.toString().equals(clin))?"SELECTED":"")%>><%=clin_name%></option>
            <%
}%>
          </select>
          <%
      rset.close();
      stmt.close();
      conn.close();
%>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Stuck in Bootstrap WysiHtml Editor 3 42
Struts tiles for layout structure along with Angular JS. 4 172
tomcat startup error 5 102
how to debug htl and js pages 8 39
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question