2 Replies Latest reply: Jan 6, 2005 1:00 PM by 796254 RSS

    [b]Java JDBC and Oracle DB URGENT HELP PLEASE[/b]

    807596
      Hello, I am a newbie. I'm very interested in Java in relation to JDBC, Oracle and SAP.I am trying to connect to an Oracle DB and I have problems to display the output on the consule in my application. What am I doing wrong here . Please help me. This is my code: Please Explain

      import java.sql.*;
      import java.sql.DriverManager;
      import java.sql.Connection;

      public class SqlConnection {

      public static void main(String[] args) {

      Class.forName("oracle.jdbc.driver.OracleDriver"); //Loading the Oracle Driver.
      Connection con = DriverManager.getConnection
      ("jdbc:orcle:thin:@34.218.5.3:1521:ruka","data","data"); //making the connection.
      Statement stmt = con.createStatement ();// Sending a query to the database
      ResultSet rs = stmt.executeQuery("SELECT man,jean,test,kok FROM sa_kostl");
      while (rs.next()) {
      String man = rs.getString("1");
      String jean = rs.getString("2");
      String test = rs.getString("3");
      String kok = rs.getString("4");
      System.out.println( man, jean, test,kok );//here where my the
      //compiler gives me errors

      }
      stmt.close();
      con.close();
      }
      }
        • 1. Re: [b]Java JDBC and Oracle DB URGENT HELP PLEASE[/b]
          796447
          duplicate post: http://forum.java.sun.com/thread.jspa?threadID=584668&messageID=2998496
          • 2. Re: [b]Java JDBC and Oracle DB URGENT HELP PLEASE[/b]
            796254
            Hello, I am a newbie. I'm very interested in Java in
            relation to JDBC, Oracle and SAP.I am trying to
            connect to an Oracle DB and I have problems to
            display the output on the consule in my application.
            What am I doing wrong here . Please help me. This is
            my code: Please Explain

            import java.sql.*;
            import java.sql.DriverManager; <--- Why do you have these (java.sql.* is enough)
            import java.sql.Connection;

            public class SqlConnection {

            public static void main(String[] args) {
            // Where's the try/catch block?

            >
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //Loading the Oracle Driver.
            Connection con = DriverManager.getConnection
            ("jdbc:orcle:thin:@34.218.5.3:1521:ruka","data","data"
            ); //making the connection.
            Statement stmt = con.createStatement ();// Sending a
            query to the database
            ResultSet rs = stmt.executeQuery("SELECT
            man,jean,test,kok FROM sa_kostl");
            while (rs.next()) {
            String man = rs.getString("1");
            String jean = rs.getString("2");
            String test = rs.getString("3");
            String kok = rs.getString("4");
            System.out.println( man, jean, test,kok );//here
            where my the
            //compiler gives me errors

            }
            stmt.close();
            con.close();
            }
            }
            The compiler is probably complaining about the lack of a try/catch block.

            The fact that you can't understand the compiler messages, and didn't read the javadocs enough to know that you needed a try/catch block, suggest to me that you need to learn a lot more about Java. This is pretty fundamental stuff.

            When you have problems, it's best to include information about what the compiler or runtime is telling. Error messages and stack traces are helpful.

            In your case the error is so elementary that more information isn't necessary.

            %