Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. String query = "select name from table1";
  2. try {
  3. con = connectionClass.CONN();
  4. stmt = con.createStatement();
  5. rs = stmt.executeQuery(query);
  6. .....
  7.  
  8. java.lang.NullPointerException:Attempt to invoke virtual method 'java.sql.Connection com.example.ashfaqafzal.emapp.ConnectionClass.CONN()' on a null object reference
  9.  
  10. public Connection CONN() {
  11. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  12. .permitAll().build();
  13. StrictMode.setThreadPolicy(policy);
  14. Connection conn = null;
  15. String ConnURL = null;
  16. try {
  17.  
  18. Class.forName(classs);
  19. ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
  20. + "databaseName=" + db + ";user=" + un + ";password="
  21. + password + ";";
  22. conn = DriverManager.getConnection(ConnURL);
  23. } catch (SQLException se) {
  24. Log.e("ERRO", se.getMessage());
  25. } catch (ClassNotFoundException e) {
  26. Log.e("ERRO", e.getMessage());
  27. } catch (Exception e) {
  28. Log.e("ERRO", e.getMessage());
  29. }
  30. return conn;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement