Results 1 to 6 of 6

Thread: [RESOLVED] How to Write SQL statements in Java Programs

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Resolved [RESOLVED] How to Write SQL statements in Java Programs

    Hi,

    How do I write SQL statements in Java code (ResultSet/Statement)...What are the delimiters for SQL statements...In VB the delimiters for SQL statements are:

    1) ' string
    2)# dates

    and so on....

    Hoping for any examples...Tutorials are also welcomed...Thanks

    Greg
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: How to Write SQL statements in Java Programs

    I'm not sure I understand your question(I'm not an SQL geek though )

    But AFAIK, SQL is to be written as a string and then passed to a method, in which case you wouldn't need a specific type for the variables themselves, it'd all be a matter of following the SQL syntax.

    Correct me if I'm wrong? =).
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: How to Write SQL statements in Java Programs

    I agree
    and for the second part, SQL statement delimiters are the same for both languages
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: How to Write SQL statements in Java Programs

    The pound sign (#) is only used in MSAccess as a date deliminater. The rest of them ususally just use a single qoute around a valid date format
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: How to Write SQL statements in Java Programs

    Hi guys,,,

    Thanks for the tips...Yup, I was referring to the sql statement being copied to a string variable..I used the single quotation in this sql statement and it did work...

    Here is the sample code:

    Code:
    String sql = "INSERT INTO DeptSelection (DeptDescription,DeptID, DeptAddress1,DeptAddress2,DeptCity,DeptPostalCode) " +
                   "VALUES('"+getDeptDescription()+ "', "+getDeptTypeId()+", '"+ getDeptAddress1()+ "',
                    '" +getDeptAddress2()+ "','"+getDeptCity()+"','"+getDeptPostalCode()+"')";
    How come java uses the symbol + in the getMethods.I just code the idea from a book?

    Greg

    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: How to Write SQL statements in Java Programs

    + sign is used for String concatenation
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width