Solved

Readiing in Db table and putting data into javascript select.

Posted on 2003-10-22
14
173 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Session migration 1 103
SimpleDateFormat.parse examples 19 89
memory representation of int[][][] a=new int[2][][]; 10 59
oracle fusion vs MQ 2 109
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When rebooting a vCenters 6.0 and try to connect using vSphere Client we get this issue "Invalid URL: The hostname could not parsed." When we get this error we need to do some changes in the vCenter advanced settings to fix the issue.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

27 Experts available now in Live!

Get 1:1 Help Now