Reputation: 839
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");
}
Upvotes: 0
Views: 147
Reputation: 2578
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();
}
}
}
Upvotes: 2