Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling JDBC from jsp through script

843838Aug 10 2005 — edited Feb 2 2006
Hi,
I want to call a jdbc through javascript from jsp.
When user clicks the button 'get list of dn', it calls the jdbc and shows the result in drop down list. So, in onclick event, i am calling a function, which itself call the jdbc and shows the result.

The below code, doesn't go to the function, but its working without calling the function.
Here is my code
<HTML>
<HEAD>
<TITLE>Picking Process</TITLE>
</HEAD>

<%@ page import = "javax.naming.InitialContext"%>
<%@ page import = "javax.sql.DataSource"%>
<%@ page import = "java.sql.Connection"%>
<%@ page import = "java.sql.Statement"%>
<%@ page import = "java.util.Vector"%>
<%@ page import = "java.sql.ResultSet"%>
<%@ page import = "javax.naming.NamingException"%>
<%@ page import = "java.io.PrintWriter"%>
<%@ page import = "java.io.IOException"%>
<%@ page import = "java.sql.SQLException"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>


<BODY>
<%! ResultSet rs = null; %>
<style type = "text/css">
H1 {
font-size : 8 pt;
font-weight : bold;
}
</style>
<H1>Picking</H1>

<% String mrvalue=null; %>
<FORM NAME="Picking">

<input type="button" value="Get list of DN" onclick=getlistdn()>

<Script>
function getlistdn()
{
alert("hi-1");

<%

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Initialized..");
}
catch (ClassNotFoundException cnfe)
{
System.out.println("Unable to load database driver");
System.out.println ("Details : " + cnfe.toString());
System.exit(0);
}
%>
<%
try
{
DriverManager.setLogStream(java.lang.System.out);
String url = "jdbc:odbc:localserver";

Connection myConnection = DriverManager.getConnection(url,"sa", "msg123v");
System.out.println("Connected to Database..");
Statement s = myConnection.createStatement();
rs = s.executeQuery("select salesorder from pickdetail");

}
catch(SQLException ex)
{
System.out.println("SQL Error : ");
System.out.println("Details :" +ex.toString());
System.exit (0);
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<SELECT NAME = "PICK" onchange=setb(this.value)>
<OPTION>" "
<%
try {
while (rs.next())
{
mrvalue=rs.getString(1);
%>


<OPTION value="<%= mrvalue%>"> <%=mrvalue%></option>


<%
}
}

catch (SQLException e)
{
System.out.println(e.toString());
}

%>

</SELECT>
}
</Script>



</FORM>

</BODY>
</HTML>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2006
Added on Aug 10 2005
3 comments
148 views