GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Oct-2005, 22:15
bryan523 bryan523 is offline
Junior Member
 
Join Date: Aug 2005
Posts: 32
bryan523 is on a distinguished road

Help in Java database connectivity with JDBC where data input by user!!


Hi all,

Can someone help me to solve this problem? As below coding, i manage to run the program and key in the date, but the selected date i just key in cannot detect by SQL? the program cannot show the data by date that just key in by user on running time??
i used firstDate to collect the date from user and at my SQL queries, i put ".....WHERE LOG_DATE = 'firstDate'......;", but the output show nothing, if i straight put ".....WHERE LOG_DATE = '2005-08-04'.....;", then no problem! This statement true or not?? what should i do?

JAVA Code:
String firstDate;
firstDate = JOptionPane.showInputDialog("Enter Date From(yy-mm-dd):");

try {
            con = DriverManager.getConnection(url, "root", "");
            data = new JDBCPieDataset(con);
            String sql = "SELECT DISTINCT PRIORITY, COUNT(*) FROM STANDARD WHERE LOG_DATE = 'firstDate' GROUP BY PRIORITY;";  //[b]PROBLEM[/b]
            data.executeQuery(sql);
            con.close();
        }

rgds,
Bryan
Last edited by LuciWiz : 27-Oct-2005 at 01:18. Reason: Please insert your Java code between [java] & [/java] tags
  #2  
Old 26-Oct-2005, 22:44
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 927
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: Help in Java database connectivity with JDBC where data input by user!!


Hi bryan,

When you enter variable name inside an string statement, it will not recognize the variable name. i.e:
JAVA Code:
            String sql = "SELECT DISTINCT PRIORITY, COUNT(*) FROM STANDARD WHERE LOG_DATE = 'firstDate' GROUP BY PRIORITY;";  //PROBLEM

The variable name firstDate is not recognized here.

So what can we do now?
Just enter the variable name by string concatenation.
i.e like this:
JAVA Code:
            String sql = "SELECT DISTINCT PRIORITY, COUNT(*) FROM STANDARD WHERE LOG_DATE = '" + firstDate + "' GROUP BY PRIORITY;";  // NO PROBLEM
This should work!

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 27-Oct-2005, 00:41
bryan523 bryan523 is offline
Junior Member
 
Join Date: Aug 2005
Posts: 32
bryan523 is on a distinguished road

Re: Help in Java database connectivity with JDBC where data input by user!!


Thanks Paramesh, without your help i think i need a lot of time to do it!

You are the greatest in the world!

Rgds,
Bryan
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
[GIM] gim.h dsmith C Programming Language 0 18-Jan-2005 08:48
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13
Script needed for letting user input a few days of data for tracking and analysis. tradertt MySQL / PHP Forum 3 06-Mar-2003 02:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.