Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rs = st.executeQuery(selectSQL);
- output = rs.getString("column");
- try{
- rs = st.executeQuery(sql);
- int i = 0;
- while(rs.next()){
- output[i] = rs.getString(column);
- // column field in the database contains multiple results, but sometimes
- // may be null
- i++;
- }
- }catch{SQLException e){
- e.printStackTrace();
- // other than tracing the exception i want to fill the array too
- }
- return output;
- String myValue = rs.getString("myColumn");
- if (rs.wasNull())
- myValue = ""; // set it to empty string as you desire.
- From java.sql.ResultSet
- boolean wasNull() throws SQLException;
- * Reports whether
- * the last column read had a value of SQL <code>NULL</code>.
- * Note that you must first call one of the getter methods
- * on a column to try to read its value and then call
- * the method <code>wasNull</code> to see if the value read was
- * SQL <code>NULL</code>.
- *
- * @return <code>true</code> if the last column value read was SQL
- * <code>NULL</code> and <code>false</code> otherwise
- * @exception SQLException if a database access error occurs or this method is
- * called on a closed result set
- */
- output = rs.getString("column");// if data is null `output` would be null, so there is no chance of NPE unless `rs` is `null`
- if(output == null){// if you fetched null value then initialize output with blank string
- output= "";
- }
- the column value; if the value is SQL NULL, the value returned is null
- Class.forName("org.sqlite.JDBC");
- con = DriverManager.getConnection("jdbc:sqlite:My_db.db");
- String sql = ("select * from cust where cust_id='" + cus + "'");
- pst = con.prepareStatement(sql);
- rs = pst.executeQuery();
- con.close();
- System.out.println(rs.getString(1));
- Class.forName("org.sqlite.JDBC");
- con = DriverManager.getConnection("jdbc:sqlite:My_db.db");
- String sql = ("select * from cust where cust_id='" + cus + "'");
- pst = con.prepareStatement(sql);
- rs = pst.executeQuery();
- System.out.println(rs.getString(1));
- con.close();
- String a;
- if(rs.getString("column") != null)
- {
- a = "Hello world!";
- }
- else
- {
- a = "Bye world!";
- }
- String name = (oRs.getString ("name_column"))! = Null? oRs.getString ("name_column"): "";
Add Comment
Please, Sign In to add comment