Link to home
Start Free TrialLog in
Avatar of princehyderabad
princehyderabad

asked on

JSP causing JS to error

hi,

Just a wired error: NullPointerException

JSP page:

...
//javascript
...
function main()
{
...
okay();
...
}
function okay()
{
 <% System.out.print("................"); %>
 alert("hi");
 return true;
}


Works fine. But when I add this code it shows me error:

function okay()
{
 <% System.out.print("................");
              //  Calling Stored Procedure
               CallableStatement cs2 = conn.prepareCall("{call abc(?) }");
               cs2.setString(1, userID);
               cs2.execute();
%>

 return true;
}

PS: All variable is define and I'm getting all valid values

thx,
PH
ASKER CERTIFIED SOLUTION
Avatar of suprapto45
suprapto45
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think that this is related to https://www.experts-exchange.com/questions/21991629/Cant-i-call-StoredProcedure-in-JSP.html

If you use
..
<%@ page import = "com.abc.Utils" %>
..
Connection conn = null;

Make sure that you have set the conn from the Utils class that you used.
Avatar of jaggernat
jaggernat

first of all, trying to access database values using a scriplet from javascript code is a very bad idea.
javascript should be exclusively used for front-end operations and NOT backend. all your java code including database connectivity should be in a java class and when you submit your jsp, you make a call to that java class and perform all the databse operations in it.
Null pointer means it is returning empty or it does not have any thing in it and that is why you are getting that error

you had a very similar problem here.
https://www.experts-exchange.com/questions/21991292/NullPointerException.html