Two Laptop Bag*
The moose likes JSP and the fly likes implementing jsp, jdbc and javascript together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "implementing jsp, jdbc and javascript together" Watch "implementing jsp, jdbc and javascript together" New topic
Author

implementing jsp, jdbc and javascript together

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
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 ]

Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implementing jsp, jdbc and javascript together