• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone, I am new to JDBC and have some questions.

How can I use a query that uses two tables: in my database I have a table Employee and a table Works_on

EMPLOYEE has the columns FNAME LNAME SSN
WORKS_ON has the columns ESSN (refering to the SSN in employee table) PNO and HOURS

i need a query that given a certain projectnumber (PNO) i get the firstname (FNAME), last name (LNAME) and the number of hours worked on a project (HOURS) for the different employees working on that project, i tried the following query but i think it is wrong:

String query2string = "SELECT FNAME, LNAME, HOURS FROM eployee_db.works_on,employee_db.employee WHERE PNO=? AND ESSN=SSN + ORDER BY LNAME;";

thanks for your help!
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roma,
Welcome to the Ranch!

It looks really close, the join part is correct. There is a stray "+" before order by, but that's probably a typo. What are your doubts about it?
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's also a ';' at the end of the SQL which shouldn't be there.
 
roma janssens
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i use eclipse for my project and when i ask to run it gives the error

SQL Exception:
ORA-00936: missing expression

when i change this query to

String query2string = "SELECT HOURS FROM eployee_db.works_onWHERE PNO=?";

the error changes to

SQL Exception:
ORA-00911: invalid character

(i suspect there are more errors in my project so i think this means the first error is due to the query being wrong)


i really should be able to get this to workasap but due to my poor knowledge of SQL i cannot understand what i am doing wrong, if anyone could help me with this i would really appreciate it
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

SELECT HOURS FROM eployee_db.works_onWHERE PNO=?


There is no space between works_on and WHERE.
eployee_db is also spelled wrong.

One thing you can do to identify these types of errors is copy the SQL into a tool such as sqlplus or toad and run it from there. Of course you'll have to change the '?' into a real value.
 
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic