Solved

Readiing in Db table and putting data into javascript select.

Posted on 2003-10-22
14
179 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 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
Technology Partners: 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 52

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

Technology Partners: 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!

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Here's how to start interacting with our community through Post.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

728 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