User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 329,051 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,605 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 146 | Replies: 3
Reply
Join Date: Aug 2007
Posts: 67
Reputation: Kusno is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster in Training

SQL Query problem

  #1  
7 Days Ago
Dear all,
I filter my query select with parameter from previous page.

SQL = "select a.KodePenyanyi, p.NamaPenyanyi, p.WebSite, a.KodeAlbum, a.NamaAlbum, NamaLabel, Tahun, a.Kaset, a.CD, a.CDImport, a.DVD, DaftarLagu, ReviewAlbum FROM masterpenyanyi p inner join masteralbum a on a.KodePenyanyi=p.KodePenyanyi inner join masterlabel on masterlabel.KodeLabel = a.KodeLabel where a.KodeAlbum='" + kodeAlbum + "'";

Result should be like this :
select a.KodePenyanyi, p.NamaPenyanyi, p.WebSite, a.KodeAlbum, a.NamaAlbum, NamaLabel, Tahun, a.Kaset, a.CD, a.CDImport, a.DVD, DaftarLagu, ReviewAlbum FROM masterpenyanyi p inner join masteralbum a on a.KodePenyanyi=p.KodePenyanyi inner join masterlabel on masterlabel.KodeLabel = a.KodeLabel where a.KodeAlbum='SID-001'

but I dont know why JSP gives this result :
select a.KodePenyanyi, p.NamaPenyanyi, p.WebSite, a.KodeAlbum, a.NamaAlbum, NamaLabel, Tahun, a.Kaset, a.CD, a.CDImport, a.DVD, DaftarLagu, ReviewAlbum FROM masterpenyanyi p inner join masteralbum a on a.KodePenyanyi=p.KodePenyanyi inner join masterlabel on masterlabel.KodeLabel = a.KodeLabel where a.KodeAlbum='"000002-0015"'

<%@ page language="java" import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<%
	ResultSet rst=null;
        Statement stmt=null;
        Connection cn = null;
        try {            
            Class.forName("com.mysql.jdbc.Driver");                           
            String url;                       
            url = "jdbc:mysql://localhost:3306/tokomusik?user=root&password=root";
            cn = DriverManager.getConnection (url);  
            stmt=cn.createStatement(); 
            String kodeAlbum;
            kodeAlbum = request.getParameter("KodeAlbum");
            String SQL;
            SQL = "select a.KodePenyanyi, p.NamaPenyanyi, p.WebSite,  a.KodeAlbum, a.NamaAlbum, NamaLabel,  Tahun, a.Kaset, a.CD, a.CDImport, a.DVD, DaftarLagu, ReviewAlbum FROM masterpenyanyi p inner join masteralbum a on a.KodePenyanyi=p.KodePenyanyi inner join masterlabel on masterlabel.KodeLabel = a.KodeLabel where a.KodeAlbum='" + kodeAlbum + "'";            rst=stmt.executeQuery(SQL);              
            out.println(SQL);
        }
        catch (SQLException se) 
        {
            out.println(se.toString());
            
        } catch (Exception ex) 
        {
            out.println(ex.toString());            
        }
%>
NEVER NEVER NEVER GIVE UP
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,546
Reputation: peter_budo will become famous soon enough peter_budo will become famous soon enough 
Rep Power: 8
Solved Threads: 149
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Posting Virtuoso

Re: SQL Query problem

  #2  
7 Days Ago
Ouch, do not put database connection in JSP! JSP is for presentation purposes. It is servlet that does logic, which include connection to DB. Also there is nothing worng with JSP (beside that DB connection part) it is your query that is wrong, work correct formula in database and then re-use it in connection
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Aug 2007
Posts: 67
Reputation: Kusno is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster in Training

Re: SQL Query problem

  #3  
6 Days Ago
Originally Posted by peter_budo View Post
Ouch, do not put database connection in JSP! JSP is for presentation purposes. It is servlet that does logic, which include connection to DB. Also there is nothing worng with JSP (beside that DB connection part) it is your query that is wrong, work correct formula in database and then re-use it in connection



Yes, I know my false. I have read these matter in others threads.
I put connection in JSP because I still don't know how to connect it to servlet.
But my problem is in my query select.

Thanks,

Kusno.
NEVER NEVER NEVER GIVE UP
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,610
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 21
Solved Threads: 297
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: SQL Query problem

  #4  
6 Days Ago
> but I dont know why JSP gives this result :

Maybe because "KodeAlbum" actually contains "000002-0015"? It would be better if you printed out the value of the form field "KodeAlbum" after form submission and made sure it is the same as you want. If yes, then the change is happening somewhere in between the request attribute being set and it's use.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 5:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC