?
Solved

Readiing in Db table and putting data into javascript select.

Posted on 2003-10-22
14
Medium Priority
?
180 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
[X]
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
  • 4
  • 4
  • 2
  • +2
14 Comments
 
LVL 3

Accepted Solution

by:
applekanna earned 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 53

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

770 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