java - SQL - how to return multiple rows with one SQL query? -


i have managed bean makes sql queries oracle database. simple example how make sql queries. table structure:

globalsettings --------------------------------- sessionttl          varchar2(40 byte) maxactiveusers  number activeusers         varchar2(20 byte) 

i use table store application settings. in example listed below can fetch 1 string 1 sql statement. want sql query fetch content of 3 rows - sessionttl, maxactiveusers, activeusers. possible?

   public string checkuserdb(string usertocheck) throws sqlexception {         string storedpassword = null;                 string sql_statement = null;          if (ds == null) throw new sqlexception();          connection conn = ds.getconnection();         if (conn == null) throw new sqlexception();           try {         conn.setautocommit(false);         boolean committed = false;             try {                    sql_statement = "select passwd users username = ?";                     preparedstatement passwordquery = conn.preparestatement(sql_statement);                    passwordquery.setstring(1, usertocheck);                     resultset result = passwordquery.executequery();                     if(result.next()){                         storedpassword = result.getstring("passwd");                    }                     conn.commit();                    committed = true;              } {                    if (!committed) conn.rollback();                    }         }             {                            conn.close();              }       return storedpassword;           }                          

p.s want content of rows.

i'm hoping understand asking for, fear don't seems simple, anyway...

i think want contents of 3 columns, not rows. , yes can, specify columns want returned in sql statement:

select sessionttl, maxactiveusers, activeusers globalsettings (condition)... 

you can use * shortcut columns iof don't want explicitly specify them:

select * globalsettings (condition)... 

some background reading on sql syntax might useful


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -