• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

implementing jsp, jdbc and javascript together

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ranchers..

here i'm facing a serious problem
this is the table view
------------------------
nameageph
----------------------
aravind23123
prasad24124
chandu25125
rony26126
praveen27127
maya28128
vijesh29129
hunky30130
siva31131

the source code for the jsp.. is this

<html>
<head>
<title>DOLOGIN
</title>
</head>
<%@ page language="java" session="true" import="java.sql.*" %>
<body>
<form method="POST" name="form1" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<select size="1" name="D1" onchange =xx() >
<option> --Select One--</option>

<%
String age[] = new String[20];
String ph[] = new String[20];
int i=0;
try
{
try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{out.println(e);
}
String dbURL = "jdbc dbc:trial";
Connection dbCon;
dbCon = DriverManager.getConnection(dbURL);
String query = "Select * from table1";
Statement stmt = dbCon.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{String name = rs.getString(1);
//out.println(name);
%>
<option value="<%=name%>"><%=name%></option>
<%
age[i]= rs.getString(2);
ph[i] = rs.getString(3);
out.println(age[i]);
out.println(ph[i]);
i++;

}
dbCon.close();
stmt.close();
}
catch(SQLException e)
{response.sendRedirect("error.html");
}
%>

</form>
</body>
</html>

<SCRIPT LANGUAGE=javascript>
<!--
function xx()
{//alert("aravind")
alert(document.form1.D1.selectedIndex)
alert(document.form1.D1.value)
alert(age[document.form1.D1.selectedIndex])
}
//-->
</SCRIPT>

the problem what i want to get is..
in the function xx()
i want to get the alert message "age" of the selected one from the combo box..

please help me

egs.. when i select aravind from the combobox..
i can get the index as 1
i can get the value as aravind
but i cannot get the corresponding age to aravind


please help me ranchers
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you're tring to access a Java array from JavaScript, which is not going to work for fundamental reasons (the Java code runs on the server, while JavaScript runs on the client). This article by JavaRanchs Bear Bibeault explains why.

I'll just point out briefly that it's considered bad design to have DB access code in a JSP, and that the use of the JDBC/ODBC bridge in a multi-threaded environment (as a web application provides) is inherently trouble-prone.
[ February 22, 2006: Message edited by: Ulf Dittmer ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic