Solved

Readiing in Db table and putting data into javascript select.

Posted on 2003-10-22
14
171 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
 
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 49

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now