Results 1 to 13 of 13
  1. #1
    aiesha is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default coding or mysql connection problem????

    When I run this code I keep getting "Unregistered User".This code is suppose to add a new admin........
    Could anyone tell me what is wrong here??...pls?



    Java Code:
    <%@ page contentType="text/html;" language="java" import="java.sql.*" errorPage="" %>
    <%
    String ent=String.valueOf(session.getAttribute("entadm"));
    if (ent.equals("yes"))
    {
    	
    Connection con=null;
    Statement smt=null;
    ResultSet rs=null;
    try
    {
    	Class.forName("com.mysql.jdbc.Driver");
    	
    	con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","");
    
    
    
    }
    catch(ClassNotFoundException ce){out.println("Check the values and try again...");}
    catch(SQLException ce){out.println("Check the values and try again...");}
    
    smt=con.createStatement();
    rs=smt.executeQuery("select max(req_id) from ant_req");
    int id;
    if(!rs.next())
    {
    	id=0;
    }
    else
    {
    	id=rs.getInt(1);
    }
    id=id+1;
    int accexi=0;
    String accno=request.getParameter("txt_accno");
    String apwd=request.getParameter("txt_pwd");
    //int crd=Integer.parseInt(request.getParameter("txt_crd"));
    String sqtn=request.getParameter("txt_sq");
    String sans=request.getParameter("txt_sa");
    String fname=request.getParameter("txt_fn");
    String sname=request.getParameter("txt_sn");
    String sex=request.getParameter("cmb_sex");
    String emailid=request.getParameter("txt_email");
    //long rphone=Long.valueOf(request.getParameter("txt_rp"));
    //long ophone=Long.valueOf(request.getParameter("txt_op"));
    String hname="Admin";
    String city=request.getParameter("txt_city");
    String branch=request.getParameter("cmb_bra");
    int age=1;
    String stime="Admin";
    String sptime="Admin";
    String tpwd=request.getParameter("txt_pwd");
    int st=3;
    int id1;
    
    rs=smt.executeQuery("select max(reg_id) from reg_info");
    if(!rs.next())
    {
    	id1=0;
    }
    else
    {
    	id1=rs.getInt(1);
    }
    id1=id1+1;
    
    String query="insert into ant_req values(" + id + "," + accexi + ",'" + accno + "','0','" + sqtn + "','" + sans + "','" + fname + "','" + sname + "','" + sex  + "','" + emailid  + "','" + request.getParameter("txt_rp")  + "','" + request.getParameter("txt_op")  + "','" + hname  + "','" + city  + "','" + branch  + "'," + age  + ",'" + stime + "','" + sptime  + "','" + tpwd + "'," + st + ")";
    String q1="insert into reg_info values(" + id1 +"," + id + ",'" + fname + "','" + sname + "'," + age + ",'admin','" + city + "','" + emailid + "','" + request.getParameter("txt_rp") + "','" + request.getParameter("txt_op") + "')";
    String q2="insert into login_info values('" + accno + "','" + apwd + "','" + sqtn + "','" + sans + "','admin'," + id1 + ")";
    
    try
    {
    	smt.executeUpdate(query);
    	smt.executeUpdate(q1);
    	smt.executeUpdate(q2);
    }
    catch(SQLException ce){ 
    	out.println("Check the values and try again...");
    	smt.close();
    	con.close();
    }
    smt.close();
    con.close();
    response.sendRedirect("ad_msg_con.htm");
    
    }
    else
    	out.println("Unregistered User");
    %>
    Database connector

    Java Code:
    package ebank;
    
    
    import java.sql.*;
    import java.io.*;
    
    public class DBOperations
    {
    	Connection con;
    	Statement smt;
    	ResultSet rs;
    
    	public void sta()
    	{
    		System.out.println("HELLO");
    	}
    
    	public void makeConnection() throws ClassNotFoundException,SQLException
    	{
    		Class.forName("com.mysql.jdbc.Driver");
    		con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","");
    	}
    
    	public ResultSet selectData(String str) throws ClassNotFoundException,SQLException
    	{
    		makeConnection();
    		smt=con.createStatement();
    		rs=smt.executeQuery(str);
    		smt.close();
    		con.close();
    		return(rs);
    	}
    
    	public void updateTable(String str) throws ClassNotFoundException,SQLException
    	{
    		makeConnection();
    		smt=con.createStatement();
    		smt.executeUpdate(str);
    		smt.close();
    		con.close();
    	}	
    }
    Last edited by aiesha; 03-19-2011 at 11:18 AM.

  2. #2
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    61
    Rep Power
    0

    Red face hi

    could post us the view logic and the input passed by you

  3. #3
    aiesha is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    well I dont actually get to insert anything cause when I run the code I get a msg says "Unregistered user"

  4. #4
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    61
    Rep Power
    0

    Default ya

    ya if you not passing anything the output which you gotten is write.

  5. #5
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    61
    Rep Power
    0

    Red face sorry

    not write correct.

  6. #6
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    61
    Rep Power
    0

    Red face sorry

    ya if you not passing anything the output which you gotten is correct.:D

  7. #7
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,798
    Rep Power
    19

    Default

    Where are you getting your error?
    Do not do this sort of thing in a JSP page, it makes it hard to debug.
    This should be some code called from a Servlet, then the result forwarded to a JSP for display.

    When catching an exception at the least print the stack trace. Don't just print a "something's gone wrong" type of message.

    ETA: But vinotht is correct (not that the almost complete lack of formatting helps). "entadm" cannot be equal to "yes".

  8. #8
    aiesha is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    IT WORKED!!!!!!
    THANK YOU SO MUCH!!!!!....You guys help me alot!! I appreciate it!

  9. #9
    seal0rd is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default Re: coding or mysql connection problem????

    can you explain what you did to make it work.... cos i av the same problem tooo... can anyone help me out

Similar Threads

  1. URL problem in mysql connection in jsp
    By gb.rashu in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 11-19-2010, 07:23 AM
  2. connection my mysql
    By pranjul137 in forum New To Java
    Replies: 5
    Last Post: 04-06-2010, 08:26 PM
  3. TWO IPs FOR MY MYSQL CONNECTION
    By tugalsan in forum JDBC
    Replies: 2
    Last Post: 03-21-2010, 08:46 PM
  4. Java-mysql connection
    By Kligham in forum New To Java
    Replies: 16
    Last Post: 11-25-2009, 01:28 PM
  5. no mysql connection
    By scchia in forum New To Java
    Replies: 12
    Last Post: 07-19-2008, 07:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •