0

i am using following code for get data from database but data is in big quantity so string is not hold all data so what is the process to get all data from database

     spst=scon.prepareStatement("SELECT dbQuery FROM alyss where license=?");
     spst.setString(1, key);
     ResultSet rs = spst.executeQuery();
     while(rs.next()){
     DBQuery = rs.getNString("dbQuery");
     }
2
  • yes i have more than 2 billion character. Commented Nov 20, 2014 at 11:13
  • Which DBMS are you using? Commented Nov 20, 2014 at 12:20

1 Answer 1

2

Use

Reader reader=rs.getNCharacterStream(columnIndex) ;

It is intended for use when accessing NCHAR,NVARCHAR and LONGNVARCHAR columns

Code

   java.sql.Statement st=connection.createStatement();
   ResultSet rs=st.executeQuery("SELECT ApplicationId FROM application");

    while(rs.next())
    {
        FileOutputStream fileOutputStream=null;
        Reader reader=null;
        try {
            fileOutputStream =   new FileOutputStream("output.txt");
            reader=rs.getNCharacterStream(1 /*you can use here column name also*/);
            int c;
            while( (c=reader.read())!=-1)
            {
                fileOutputStream.write(c) ;
            }

        }           
        catch(Exception e){}
        finally {
            if (reader != null) {
                reader.close();
            }
            if (fileOutputStream != null) {
                fileOutputStream.close();
            }
        }
    }
Sign up to request clarification or add additional context in comments.

2 Comments

how can save these data in a file
Vishvesh this code is not working properly this code give java.lang.NullPointerException Execption

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.