I have a serious problem.
Firstly, I am trying to retrieve values from my database by individual scripts on my JSP pages. Here is part of the code:
<%String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;`
Statement stmt=null;
try{
String url="jdbc:mysql://localhost:3306/MajorProjectDB?user=cdsadmin2&password=enjoyit";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
String name= request.getRemoteUser();
rst=stmt.executeQuery("select verifycode from Staff where name='"+name+"'");
%>
<%
int no=1;`
while(rst.next()){
%>
<%=no%>
<%=rst.getString("VERIFYCODE")%>
<%String code= request.getParameter("code"); %>
<% } %>
In this code I am storing a string from VERIFYCODE column in my Staff table.
I will be able to compare it with the user input within the form by using a getparameter
.
HOWEVER, the comparison should be done with onClick
function, but due to the fact that it is running as an individual script, it cannot be attached to the onClick
function.
Now I am trying to insert an SQL statement in the following javascript in my JSP page:
<script type="text/javascript">
function verifyCode(){
// a SELECT sql statement which gets String from database
//comparison between String retrieved from database and user input
if{
}
else{
}
}
</script>
May I know if anyone has any solution? Or is there a easier method of doing it? Thanks in advance, any help is greatly appreciated!