I am trying to execute a sql query using prepared statement but it is returning empty valueAdd a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeCan I concatenate multiple MySQL rows into one field?Inserting multiple rows in a single SQL query?How do I limit the number of rows returned by an Oracle query after ordering?When should I use cross apply over inner join?How can I do an UPDATE statement with JOIN in SQL?Finding duplicate values in a SQL tableNested select statement in SQL ServerSQL select only rows with max value on a column

Sinning and G-d's will, what's wrong with this logic?

1kV DC Circuit - Insulation on ground wire?

Was the lunar landing site always in the same plane as the CM's orbit?

Round away from zero

Why is Sojdlg123aljg a common password?

In apex, how to replace the value in the string

What's in a druid's grove?

Looking for the comic book where Spider-Man was [mistakenly] addressed as Super-Man

What do English-speaking kids call ice-cream on a stick?

Connect the wires without setting off the bomb

What makes an ending "happy"?

Why are UK MPs allowed to not vote (but it counts as a no)?

Entering the US with dual citizenship but US passport is long expired?

What quests do you need to stop at before you make an enemy of a faction for each faction?

Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?

Is it right to use the ideas of non-winning designers in a design contest?

I won a car in a poker game. How is that taxed in Canada?

How does the UK House of Commons think they can prolong the deadline of Brexit?

Why did Boris Johnson call for new elections?

Supervisor wants me to support a diploma-thesis SW tool after I graduated

What is the justification for Dirac's large numbers hypothesis?

How can I hint that my character isn't real?

First Number to Contain Each Letter

Can you create water inside someone's mouth?



I am trying to execute a sql query using prepared statement but it is returning empty value


Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeCan I concatenate multiple MySQL rows into one field?Inserting multiple rows in a single SQL query?How do I limit the number of rows returned by an Oracle query after ordering?When should I use cross apply over inner join?How can I do an UPDATE statement with JOIN in SQL?Finding duplicate values in a SQL tableNested select statement in SQL ServerSQL select only rows with max value on a column






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.preparedStatement(sql);
ResultSet rs = ps.executeQuery();


While execute this I get result set as empty. What is the issue with this..










share|improve this question


























  • what is s_upload_file.nextvalue ?

    – Akash Shah
    Mar 28 at 5:17











  • Upload_file is a table name and it has a sequence number column here I am trying to access it by pseudocolumn .. sorry its Nextval I had edited

    – Vignesh Murugesan
    Mar 28 at 5:20











  • Its running directly... Could you suggest a way to find the next value of the sequence number column in db?

    – Vignesh Murugesan
    Mar 28 at 5:22











  • Did you go through rs.next()?

    – Hasitha M Jayawardana
    Mar 28 at 5:27











  • Thanks hasitha I got the value when iterate through RS.next()..

    – Vignesh Murugesan
    Mar 28 at 5:35

















0















String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.preparedStatement(sql);
ResultSet rs = ps.executeQuery();


While execute this I get result set as empty. What is the issue with this..










share|improve this question


























  • what is s_upload_file.nextvalue ?

    – Akash Shah
    Mar 28 at 5:17











  • Upload_file is a table name and it has a sequence number column here I am trying to access it by pseudocolumn .. sorry its Nextval I had edited

    – Vignesh Murugesan
    Mar 28 at 5:20











  • Its running directly... Could you suggest a way to find the next value of the sequence number column in db?

    – Vignesh Murugesan
    Mar 28 at 5:22











  • Did you go through rs.next()?

    – Hasitha M Jayawardana
    Mar 28 at 5:27











  • Thanks hasitha I got the value when iterate through RS.next()..

    – Vignesh Murugesan
    Mar 28 at 5:35













0












0








0


1






String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.preparedStatement(sql);
ResultSet rs = ps.executeQuery();


While execute this I get result set as empty. What is the issue with this..










share|improve this question
















String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.preparedStatement(sql);
ResultSet rs = ps.executeQuery();


While execute this I get result set as empty. What is the issue with this..







java sql oracle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 5:19







Vignesh Murugesan

















asked Mar 28 at 5:13









Vignesh MurugesanVignesh Murugesan

33 bronze badges




33 bronze badges















  • what is s_upload_file.nextvalue ?

    – Akash Shah
    Mar 28 at 5:17











  • Upload_file is a table name and it has a sequence number column here I am trying to access it by pseudocolumn .. sorry its Nextval I had edited

    – Vignesh Murugesan
    Mar 28 at 5:20











  • Its running directly... Could you suggest a way to find the next value of the sequence number column in db?

    – Vignesh Murugesan
    Mar 28 at 5:22











  • Did you go through rs.next()?

    – Hasitha M Jayawardana
    Mar 28 at 5:27











  • Thanks hasitha I got the value when iterate through RS.next()..

    – Vignesh Murugesan
    Mar 28 at 5:35

















  • what is s_upload_file.nextvalue ?

    – Akash Shah
    Mar 28 at 5:17











  • Upload_file is a table name and it has a sequence number column here I am trying to access it by pseudocolumn .. sorry its Nextval I had edited

    – Vignesh Murugesan
    Mar 28 at 5:20











  • Its running directly... Could you suggest a way to find the next value of the sequence number column in db?

    – Vignesh Murugesan
    Mar 28 at 5:22











  • Did you go through rs.next()?

    – Hasitha M Jayawardana
    Mar 28 at 5:27











  • Thanks hasitha I got the value when iterate through RS.next()..

    – Vignesh Murugesan
    Mar 28 at 5:35
















what is s_upload_file.nextvalue ?

– Akash Shah
Mar 28 at 5:17





what is s_upload_file.nextvalue ?

– Akash Shah
Mar 28 at 5:17













Upload_file is a table name and it has a sequence number column here I am trying to access it by pseudocolumn .. sorry its Nextval I had edited

– Vignesh Murugesan
Mar 28 at 5:20





Upload_file is a table name and it has a sequence number column here I am trying to access it by pseudocolumn .. sorry its Nextval I had edited

– Vignesh Murugesan
Mar 28 at 5:20













Its running directly... Could you suggest a way to find the next value of the sequence number column in db?

– Vignesh Murugesan
Mar 28 at 5:22





Its running directly... Could you suggest a way to find the next value of the sequence number column in db?

– Vignesh Murugesan
Mar 28 at 5:22













Did you go through rs.next()?

– Hasitha M Jayawardana
Mar 28 at 5:27





Did you go through rs.next()?

– Hasitha M Jayawardana
Mar 28 at 5:27













Thanks hasitha I got the value when iterate through RS.next()..

– Vignesh Murugesan
Mar 28 at 5:35





Thanks hasitha I got the value when iterate through RS.next()..

– Vignesh Murugesan
Mar 28 at 5:35












4 Answers
4






active

oldest

votes


















0
















you should try something like this,



 String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
if (rs.next())

int var2= rs.getInt(1);






share|improve this answer






















  • 1





    Please post code that makes sense and compiles

    – Joakim Danielson
    Mar 28 at 7:07


















1
















There are many answers already, but I will try to give you a full scope of the answer.



public static Connection getConnection_Test() throws Exception

try

String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/Database_Name";
String username = "root";
String pass = "";
Class.forName(driver);

Connection conn = DriverManager.getConnection(url, username, pass);
System.out.println("Success!");

String query = "SELECT S_UPLOAD_FILE.NEXTVAL from dual n ";

PreparedStatement st = conn.prepareStatement(query);
ResultSet rs = st.executeQuery();
while(rs.next())
int NEXTVALUE = rs.getInt(1);
System.out.println(NEXTVALUE);


rs.close();
st.close();

return conn;
catch (Exception e)
System.out.println(e);



return null;







share|improve this answer
































    0
















    You can get values through rs.next(),



    String sql = "select s_upload_file.NEXTVAL from dual";
    PreparedStatement pst = conn.prepareStatement(sql);
    synchronized( this )
    ResultSet rs = pst.executeQuery();
    if(rs.next())
    long nxtVal = rs.getLong(1);






    share|improve this answer
































      0
















      Have you tried something like this?



      /* not mandatory but give an alias to your column in select */
      if(rs.next())
      int nextval = rs.getInt(1);
      System.out.println(nextval)






      share|improve this answer



























        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390595%2fi-am-trying-to-execute-a-sql-query-using-prepared-statement-but-it-is-returning%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0
















        you should try something like this,



         String sql = "select s_upload_file.NEXTVAL from dual" ;
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next())

        int var2= rs.getInt(1);






        share|improve this answer






















        • 1





          Please post code that makes sense and compiles

          – Joakim Danielson
          Mar 28 at 7:07















        0
















        you should try something like this,



         String sql = "select s_upload_file.NEXTVAL from dual" ;
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next())

        int var2= rs.getInt(1);






        share|improve this answer






















        • 1





          Please post code that makes sense and compiles

          – Joakim Danielson
          Mar 28 at 7:07













        0














        0










        0









        you should try something like this,



         String sql = "select s_upload_file.NEXTVAL from dual" ;
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next())

        int var2= rs.getInt(1);






        share|improve this answer















        you should try something like this,



         String sql = "select s_upload_file.NEXTVAL from dual" ;
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next())

        int var2= rs.getInt(1);







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 8:15









        a_horse_with_no_name

        331k54 gold badges515 silver badges609 bronze badges




        331k54 gold badges515 silver badges609 bronze badges










        answered Mar 28 at 7:03









        Ajith DeivamAjith Deivam

        1224 silver badges17 bronze badges




        1224 silver badges17 bronze badges










        • 1





          Please post code that makes sense and compiles

          – Joakim Danielson
          Mar 28 at 7:07












        • 1





          Please post code that makes sense and compiles

          – Joakim Danielson
          Mar 28 at 7:07







        1




        1





        Please post code that makes sense and compiles

        – Joakim Danielson
        Mar 28 at 7:07





        Please post code that makes sense and compiles

        – Joakim Danielson
        Mar 28 at 7:07













        1
















        There are many answers already, but I will try to give you a full scope of the answer.



        public static Connection getConnection_Test() throws Exception

        try

        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/Database_Name";
        String username = "root";
        String pass = "";
        Class.forName(driver);

        Connection conn = DriverManager.getConnection(url, username, pass);
        System.out.println("Success!");

        String query = "SELECT S_UPLOAD_FILE.NEXTVAL from dual n ";

        PreparedStatement st = conn.prepareStatement(query);
        ResultSet rs = st.executeQuery();
        while(rs.next())
        int NEXTVALUE = rs.getInt(1);
        System.out.println(NEXTVALUE);


        rs.close();
        st.close();

        return conn;
        catch (Exception e)
        System.out.println(e);



        return null;







        share|improve this answer





























          1
















          There are many answers already, but I will try to give you a full scope of the answer.



          public static Connection getConnection_Test() throws Exception

          try

          String driver = "com.mysql.cj.jdbc.Driver";
          String url = "jdbc:mysql://localhost:3306/Database_Name";
          String username = "root";
          String pass = "";
          Class.forName(driver);

          Connection conn = DriverManager.getConnection(url, username, pass);
          System.out.println("Success!");

          String query = "SELECT S_UPLOAD_FILE.NEXTVAL from dual n ";

          PreparedStatement st = conn.prepareStatement(query);
          ResultSet rs = st.executeQuery();
          while(rs.next())
          int NEXTVALUE = rs.getInt(1);
          System.out.println(NEXTVALUE);


          rs.close();
          st.close();

          return conn;
          catch (Exception e)
          System.out.println(e);



          return null;







          share|improve this answer



























            1














            1










            1









            There are many answers already, but I will try to give you a full scope of the answer.



            public static Connection getConnection_Test() throws Exception

            try

            String driver = "com.mysql.cj.jdbc.Driver";
            String url = "jdbc:mysql://localhost:3306/Database_Name";
            String username = "root";
            String pass = "";
            Class.forName(driver);

            Connection conn = DriverManager.getConnection(url, username, pass);
            System.out.println("Success!");

            String query = "SELECT S_UPLOAD_FILE.NEXTVAL from dual n ";

            PreparedStatement st = conn.prepareStatement(query);
            ResultSet rs = st.executeQuery();
            while(rs.next())
            int NEXTVALUE = rs.getInt(1);
            System.out.println(NEXTVALUE);


            rs.close();
            st.close();

            return conn;
            catch (Exception e)
            System.out.println(e);



            return null;







            share|improve this answer













            There are many answers already, but I will try to give you a full scope of the answer.



            public static Connection getConnection_Test() throws Exception

            try

            String driver = "com.mysql.cj.jdbc.Driver";
            String url = "jdbc:mysql://localhost:3306/Database_Name";
            String username = "root";
            String pass = "";
            Class.forName(driver);

            Connection conn = DriverManager.getConnection(url, username, pass);
            System.out.println("Success!");

            String query = "SELECT S_UPLOAD_FILE.NEXTVAL from dual n ";

            PreparedStatement st = conn.prepareStatement(query);
            ResultSet rs = st.executeQuery();
            while(rs.next())
            int NEXTVALUE = rs.getInt(1);
            System.out.println(NEXTVALUE);


            rs.close();
            st.close();

            return conn;
            catch (Exception e)
            System.out.println(e);



            return null;








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 10:34









            Aris MistAris Mist

            714 bronze badges




            714 bronze badges
























                0
















                You can get values through rs.next(),



                String sql = "select s_upload_file.NEXTVAL from dual";
                PreparedStatement pst = conn.prepareStatement(sql);
                synchronized( this )
                ResultSet rs = pst.executeQuery();
                if(rs.next())
                long nxtVal = rs.getLong(1);






                share|improve this answer





























                  0
















                  You can get values through rs.next(),



                  String sql = "select s_upload_file.NEXTVAL from dual";
                  PreparedStatement pst = conn.prepareStatement(sql);
                  synchronized( this )
                  ResultSet rs = pst.executeQuery();
                  if(rs.next())
                  long nxtVal = rs.getLong(1);






                  share|improve this answer



























                    0














                    0










                    0









                    You can get values through rs.next(),



                    String sql = "select s_upload_file.NEXTVAL from dual";
                    PreparedStatement pst = conn.prepareStatement(sql);
                    synchronized( this )
                    ResultSet rs = pst.executeQuery();
                    if(rs.next())
                    long nxtVal = rs.getLong(1);






                    share|improve this answer













                    You can get values through rs.next(),



                    String sql = "select s_upload_file.NEXTVAL from dual";
                    PreparedStatement pst = conn.prepareStatement(sql);
                    synchronized( this )
                    ResultSet rs = pst.executeQuery();
                    if(rs.next())
                    long nxtVal = rs.getLong(1);







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 28 at 5:38









                    Hasitha M JayawardanaHasitha M Jayawardana

                    1,4922 gold badges9 silver badges26 bronze badges




                    1,4922 gold badges9 silver badges26 bronze badges
























                        0
















                        Have you tried something like this?



                        /* not mandatory but give an alias to your column in select */
                        if(rs.next())
                        int nextval = rs.getInt(1);
                        System.out.println(nextval)






                        share|improve this answer





























                          0
















                          Have you tried something like this?



                          /* not mandatory but give an alias to your column in select */
                          if(rs.next())
                          int nextval = rs.getInt(1);
                          System.out.println(nextval)






                          share|improve this answer



























                            0














                            0










                            0









                            Have you tried something like this?



                            /* not mandatory but give an alias to your column in select */
                            if(rs.next())
                            int nextval = rs.getInt(1);
                            System.out.println(nextval)






                            share|improve this answer













                            Have you tried something like this?



                            /* not mandatory but give an alias to your column in select */
                            if(rs.next())
                            int nextval = rs.getInt(1);
                            System.out.println(nextval)







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 28 at 5:39









                            GroGro

                            8216 silver badges13 bronze badges




                            8216 silver badges13 bronze badges































                                draft saved

                                draft discarded















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390595%2fi-am-trying-to-execute-a-sql-query-using-prepared-statement-but-it-is-returning%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript