Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack (2) Thread Tools Search this Thread Display Modes
Old 06-03-2007, 11:23 PM   2 links from elsewhere to this Post. Click to view. #1 (permalink)
True Techie
 
nithinks's Avatar
 
Join Date: Apr 2005
Posts: 260
Question Whats wrong? JSP in netbeans?


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://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").newInstan ce();
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?
__________________
http://www.mytechyard.com/
nithinks is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 07-03-2007, 12:24 AM   #2 (permalink)
In The Zone
 
::cyborg::'s Avatar
 
Join Date: Oct 2005
Location: NEW DELHI
Posts: 436
Default Re: Whats wrong? JSP in netbeans?

write down system before the "out.println"
__________________
:)) - KEEP SMILING
::cyborg:: is offline  
Old 07-03-2007, 06:38 AM   #3 (permalink)
True Techie
 
nithinks's Avatar
 
Join Date: Apr 2005
Posts: 260
Default Re: Whats wrong? JSP in netbeans?

no.. not working...
__________________
http://www.mytechyard.com/
nithinks is offline  
Old 07-03-2007, 09:40 AM   #4 (permalink)
Indian by heart
 
planetcall's Avatar
 
Join Date: Nov 2003
Location: Bangalore
Posts: 343
Default Re: Whats wrong? JSP in netbeans?

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.
__________________
प्रासादशिखरेऽपि सन्न काको गरुडायते ॥
No matter how high a fool may rise, he remains a fool -RigVeda
planetcall is offline  
Old 07-03-2007, 11:10 PM   #5 (permalink)
True Techie
 
nithinks's Avatar
 
Join Date: Apr 2005
Posts: 260
Default Re: Whats wrong? JSP in netbeans?

im getting error for using "where" any way to solve this?
__________
problem solved.. i used LIKE instead of = near 'where'
__________________
http://www.mytechyard.com/

Last edited by nithinks; 07-03-2007 at 11:10 PM. Reason: Automerged Doublepost
nithinks is offline  
Old 08-03-2007, 12:05 AM   #6 (permalink)
Indian by heart
 
planetcall's Avatar
 
Join Date: Nov 2003
Location: Bangalore
Posts: 343
Default Re: Whats wrong? JSP in netbeans?

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.
__________________
प्रासादशिखरेऽपि सन्न काको गरुडायते ॥
No matter how high a fool may rise, he remains a fool -RigVeda
planetcall is offline  
Old 08-03-2007, 05:08 AM   #7 (permalink)
In The Zone
 
Join Date: Oct 2006
Location: Mumbai
Posts: 365
Default Re: Whats wrong? JSP in netbeans?

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

Code:
 
<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>
__________________
Dhiraj Thakur
thakur.dheeraj(@)gmail.com
Desi-Tek.com is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.thinkdigit.com/forum/qna-read-only/51600-whats-wrong-jsp-netbeans.html
Posted By For Type Date
Java na webovém serveru: první web - Zdroják This thread Refback 25-04-2012 02:35 AM
Java na webovém serveru: první web - Zdroják This thread Refback 30-06-2010 10:12 PM

 
Latest Threads
- by clmlbx
- by abhidev
- by Sarath
- by ico
- by clinton

Advertisement




All times are GMT +5.5. The time now is 02:39 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2