Results 1 to 13 of 13
- 03-19-2011, 11:13 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
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?
Database connectorJava 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"); %>
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.
- 03-20-2011, 02:42 PM #2
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
hi
could post us the view logic and the input passed by you
- 03-20-2011, 03:13 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
well I dont actually get to insert anything cause when I run the code I get a msg says "Unregistered user"
- 03-20-2011, 04:32 PM #4
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
ya
ya if you not passing anything the output which you gotten is write.
- 03-20-2011, 04:55 PM #5
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
sorry
not write correct.
- 03-20-2011, 04:56 PM #6
Member
- Join Date
- Mar 2011
- Location
- chennai
- Posts
- 55
- Rep Power
- 0
sorry
ya if you not passing anything the output which you gotten is correct.:D
- 03-22-2011, 01:52 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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".
- 03-22-2011, 07:07 PM #8
Member
- Join Date
- Mar 2011
- Posts
- 5
- Rep Power
- 0
IT WORKED!!!!!!
THANK YOU SO MUCH!!!!!....You guys help me alot!! I appreciate it!
- 10-20-2011, 12:30 PM #9
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
URL problem in mysql connection in jsp
By gb.rashu in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 11-19-2010, 07:23 AM -
connection my mysql
By pranjul137 in forum New To JavaReplies: 5Last Post: 04-06-2010, 08:26 PM -
TWO IPs FOR MY MYSQL CONNECTION
By tugalsan in forum JDBCReplies: 2Last Post: 03-21-2010, 08:46 PM -
Java-mysql connection
By Kligham in forum New To JavaReplies: 16Last Post: 11-25-2009, 01:28 PM -
no mysql connection
By scchia in forum New To JavaReplies: 12Last Post: 07-19-2008, 07:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks