invalid column name
hi all this is my jsp code and following is the error pls. hlp me.
<HTML>
<HEAD>
<TITLE>COnsignment Tracking </TITLE>
<META NAME="author" CONTENT="Marty Hall -- hall@apl.jhu.edu">
<META NAME="keywords"
CONTENT="JSP,JavaServer Pages,servlets">
<META NAME="description"
CONTENT="A quick example of the four main JSP tags.">
<LINK REL=STYLESHEET
HREF="My-Style-Sheet.css"
TYPE="text/css">
</HEAD>
<BODY BGCOLOR="#FDF5E6" TEXT="#000000" LINK="#0000EE"
VLINK="#551A8B" ALINK="#FF0000">
<CENTER>
<TABLE BORDER=20 BGCOLOR="#EF842">
<TR><TH CLASS="TITLE">
Consignment Tracking</TABLE>
</CENTER>
<P>
Login Status:
<UL>
<%@page import ="java.sql.*"%>
<%
String xaccode;
String xuid,xupas;
xuid=request.getParameter("uid");
xupas=request.getParameter("upass");
Connection conn=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:Track","","");
String s="SELECT accode FROM USERDTL WHERE ID=xuid AND PASS='ROOT' ";
Statement stm=null;
stm = conn.createStatement();
ResultSet r=stm.executeQuery(s);
if(r!=null)
{ %>
<--jsp:forward page="/remuid.jsp"/-->
<% } else { %>
Sorry!!!! login failed
<% }
}
catch(Exception exc)
{out.println(exc.toString()+"<br>");}
%>
</UL>
</BODY>
</HTML>
ERROR : java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'xuid'.
# 2
Please, please use code tags! It is so hard to read your post!
The above poster is right but your problem is that you haven't used single quotes (') and you've put your xuid String reference as part of your query string.
Your query should be like this; notice the changes around xuid
String s="SELECT accode FROM USERDTL WHERE ID='" + xuid + "' AND PASS='ROOT' ";
Though as I've learnt recently, you should use PreparedStatements instead of Statements. It'll help you avoid errors like this.
# 3
It's recommended to use a servlet and not a jsp for authentication.
take a look at this jsp plz:
<%@page import="java.sql.*"%>
<HTML>
<HEAD>
<TITLE>COnsignment Tracking</TITLE>
<META NAME="author" CONTENT="Marty Hall -- hall@apl.jhu.edu">
<META NAME="keywords" CONTENT="JSP,JavaServer Pages,servlets">
<META NAME="description"
CONTENT="A quick example of the four main JSP tags.">
<LINK REL=STYLESHEET HREF="My-Style-Sheet.css" TYPE="text/css">
</HEAD>
<BODY BGCOLOR="#FDF5E6" TEXT="#000000" LINK="#0000EE" VLINK="#551A8B"
ALINK="#FF0000">
<CENTER>
<TABLE BORDER=20 BGCOLOR="#EF842">
<TR>
<TH CLASS="TITLE">Consignment Tracking</TH>
</TR>
</TABLE>
</CENTER>
Login Status:
<UL>
<%
String xuid, xupas;
xuid = request.getParameter("uid");
xupas = request.getParameter("upass");
Connection conn = null;
boolean loginOk = false;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Track", "", "");
String s = "SELECT accode FROM USERDTL WHERE ID='"+xuid+"' AND PASS='"+xupas+"' ";
Statement stm = null;
stm = conn.createStatement();
ResultSet rs = stm.executeQuery(s);////////////////EXECUTE QUERY NEVER RETURNS NULL !!!!!!!!!!!!!!!!!!!!
if (rs.next()) {
%>
<jsp:forward page="/remuid.jsp" />
<%
} else {
%>
<li> Sorry!!!! login failed
<%
}
} catch (Exception exc) {
out.println(exc.toString() + "<li>");
}
%>
</UL>
</BODY>
</HTML>
Hope That Helps