Guest User

Untitled

a guest
Jun 7th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. rs = st.executeQuery(selectSQL);
  2.  
  3. output = rs.getString("column");
  4.  
  5. try{
  6. rs = st.executeQuery(sql);
  7.  
  8. int i = 0;
  9. while(rs.next()){
  10. output[i] = rs.getString(column);
  11. // column field in the database contains multiple results, but sometimes
  12. // may be null
  13. i++;
  14. }
  15. }catch{SQLException e){
  16. e.printStackTrace();
  17. // other than tracing the exception i want to fill the array too
  18. }
  19. return output;
  20.  
  21. String myValue = rs.getString("myColumn");
  22. if (rs.wasNull())
  23. myValue = ""; // set it to empty string as you desire.
  24.  
  25. From java.sql.ResultSet
  26. boolean wasNull() throws SQLException;
  27.  
  28. * Reports whether
  29. * the last column read had a value of SQL <code>NULL</code>.
  30. * Note that you must first call one of the getter methods
  31. * on a column to try to read its value and then call
  32. * the method <code>wasNull</code> to see if the value read was
  33. * SQL <code>NULL</code>.
  34. *
  35. * @return <code>true</code> if the last column value read was SQL
  36. * <code>NULL</code> and <code>false</code> otherwise
  37. * @exception SQLException if a database access error occurs or this method is
  38. * called on a closed result set
  39. */
  40.  
  41. output = rs.getString("column");// if data is null `output` would be null, so there is no chance of NPE unless `rs` is `null`
  42.  
  43. if(output == null){// if you fetched null value then initialize output with blank string
  44. output= "";
  45. }
  46.  
  47. the column value; if the value is SQL NULL, the value returned is null
  48.  
  49. Class.forName("org.sqlite.JDBC");
  50. con = DriverManager.getConnection("jdbc:sqlite:My_db.db");
  51. String sql = ("select * from cust where cust_id='" + cus + "'");
  52. pst = con.prepareStatement(sql);
  53. rs = pst.executeQuery();
  54. con.close();
  55. System.out.println(rs.getString(1));
  56.  
  57. Class.forName("org.sqlite.JDBC");
  58. con = DriverManager.getConnection("jdbc:sqlite:My_db.db");
  59. String sql = ("select * from cust where cust_id='" + cus + "'");
  60. pst = con.prepareStatement(sql);
  61. rs = pst.executeQuery();
  62. System.out.println(rs.getString(1));
  63. con.close();
  64.  
  65. String a;
  66. if(rs.getString("column") != null)
  67. {
  68. a = "Hello world!";
  69. }
  70. else
  71. {
  72. a = "Bye world!";
  73. }
  74.  
  75. String name = (oRs.getString ("name_column"))! = Null? oRs.getString ("name_column"): "";
Add Comment
Please, Sign In to add comment