# Whats wrong? JSP in netbeans?



## nithinks (Mar 6, 2007)

<%@ taglib prefix="c" uri="*java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="*java.sun.com/jsp/jstl/sql" %>
<HTML> 
<HEAD> 
<%@page import="java.io.*" import="java.lang.*" import="java.sql.*" %> 
<TITLE>JSP Example 2</TITLE> 
</HEAD> 
<BODY> 
<H1>JSP Example 3</H1> 
<% 
String uid, upwd, dpwd ; 
Connection dbconn; 
ResultSet results; 
PreparedStatement sql; 
try 
{ 
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
try
{ 

dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root",""); 
uid = request.getParameter("nme"); 
upwd = request.getParameter("pwd"); 
sql = dbconn.prepareStatement("SELECT anm FROM login WHERE nm='"+uid+"'"); 

results = sql.executeQuery(); 
dpwd="admin";
dpwd = results.getString("anm"); 

%>
<p><%= dpwd%></p>
<%
}catch (SQLException s) 
{ 
out.println("SQL Error<br>"); 
} 
} 
catch (ClassNotFoundException err) 
{ 
out.println("Class loading error"); 
} 
%> 

</BODY> 
</HTML>
------------------------------------------
The above program gives SQL exception why? can you give me the corrected code?


----------



## ::cyborg:: (Mar 7, 2007)

write down system before the "out.println"


----------



## nithinks (Mar 7, 2007)

no.. not working...


----------



## planetcall (Mar 7, 2007)

I am not into JSP but I can see that in the exception block you are throwing a custom string. I would suggest you rather print out the Exception message and Stack Trace instead of printing "SQL Exception".  I hope that will give you greater insight of what is happening.


----------



## nithinks (Mar 7, 2007)

im getting error for using "where" any way to solve this?
__________
problem solved.. i used LIKE instead of = near 'where'


----------



## planetcall (Mar 8, 2007)

its good you did it yourself. Always remember that Exceptions are meant not just to throw a custom string but they are powerful tools for showing you the precise information about the error/crash.


----------



## Desi-Tek.com (Mar 8, 2007)

u r mixing business logic with presentation? this is not good


```
<HTML>
<HEAD>
<%@ page import="java.sql.*" %>
<TITLE>JSP Example 2</TITLE>
</HEAD>
<BODY>
<H1>JSP Example 3</H1>
<%
  String uid, upwd, dpwd;
  String Connection = dbconn;
  String ResultSet = results;
  String PreparedStatement = sql;
  try {
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    dbconn = DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "");
    uid = request.getParameter("nme");
    upwd = request.getParameter("pwd");
    sql = dbconn.prepareStatement("SELECT anm FROM login WHERE nm='" + uid + "'");
    results = sql.executeQuery();
    dpwd = "admin";
    dpwd = results.getString("anm");
%>
<p><%= dpwd%></p>
<%
  } catch (SQLException s) {
    out.println("SQL Error<br>");
  }
  catch (ClassNotFoundException err) {
    out.println("Class loading error");
  }
  }
%>
</BODY>
</HTML>
```


----------

