This discussion is archived
2 Replies Latest reply: Apr 28, 2013 4:28 AM by Hoek RSS

Oracle and Java

1005943 Newbie
Currently Being Moderated
Hi!

How can I write a query in Java to retrieve data from Oracle database, if I want to put some parameters from my Java application in that query?
For example:

String username = userName.getText().toString();
String pass = password.getText().toString();
String command = "SELECT UserName, Password FROM Users WHERE UserName='username' and Password = 'password'";

So how do I put strings username and password into this query?

In c# and I do it like this:

SqlCommand cmd = new SqlCommand("SELECT * from korisnici where korisnicko_ime = @korisnicko_ime2 and lozinka = @lozinka2", con);
cmd.Parameters.AddWithValue("korisnicko_ime2", kor_ime.Text);
cmd.Parameters.AddWithValue("lozinka2", lozinka.Text);
dr = cmd.ExecuteReader();

Where can I find some materials to learn more about this?
  • 1. Re: Oracle and Java
    Hoek Guru
    Currently Being Moderated
    Welcome to the SQL and PL/SQL Forum.
    I guess you're better off in the Forums under
    https://forums.oracle.com/forums/category.jspa?categoryID=500
    https://forums.oracle.com/forums/category.jspa?categoryID=285
    and/or see the Java Developer's Guide: http://docs.oracle.com/cd/E11882_01/appdev.112/e12137/toc.htm

    Edited by: Hoek on Apr 28, 2013 1:27 PM
  • 2. Re: Oracle and Java
    1005943 Newbie
    Currently Being Moderated
    I solved my problem now but I will check this links.
    Thanks

    Edited by: 1002940 on Apr 28, 2013 4:29 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points