0

I am trying to enter the email field value to my SQL Oracle query. Is there any way I can do that?

<input type="email" id="email" name="email" autocomplete="off" placeholder="Enter your e-mail" required/>
<% 
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","h");

Statement st = con.createStatement();
String s1 ="select email from GI where email='**emailEnteredValueHere**'"; <%--here entered email value --%>
ResultSet rs1 = st.executeQuery(s1);
String dbemail = "";
rs1.next();
dbemail = rs1.getString(1);
out.println(dbemail);
%>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    Use bind variables and not string concatenation (or template strings). – MT0 Mar 05 '22 at 18:18
  • @MT0 Sorry I do not know what you are trying to say. I am new to the this. I want my code to check in runtime like user input the email value then if it is already exist in database then it will give a pop-up saying re-enter different email – DarK_ CodeR Mar 06 '22 at 07:41
  • First of all you should learn how JSP works, you will have to collect the data on a jsp view, POST 'em to a back-end servlet, in there perform the actualy database work, then forward the results to another JSP to present the results. Tbh I'd start from there. – BigMike Mar 06 '22 at 13:44
  • 1
    @BigMike I followed a different approach but I changed my code a little bit and it worked but not the way I wanted it but fine for now. I wanted to work my idea to work on same page but it is not possible without using the frameworks I think. – DarK_ CodeR Mar 08 '22 at 19:17
  • for simple flows I use this approach: Servlet.doGet() presents the data input view. Servlet.doPost() contains the actual update/business logic and ends with a forward to a result view (same servlet, always in GET, but with a params/indicator we're at the end of the flow). The servlet just renders a different JSP in this case. (You may take a look at how https://docs.oracle.com/javaee/7/api/javax/servlet/RequestDispatcher.html works) – BigMike Mar 09 '22 at 08:54
  • you may also check https://stackoverflow.com/questions/5003142/show-jdbc-resultset-in-html-in-jsp-page-using-mvc-and-dao-pattern top answer. – BigMike Mar 09 '22 at 08:56
  • It seems I typed wrong code somewhere i retyped the code. It is working now, thanks for the help. @BigMike – DarK_ CodeR Apr 26 '22 at 17:02

0 Answers0