Advertisement
Guest User

Untitled

a guest
Mar 20th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public void ConnectToDatabase() {
  2. try {
  3. String connectionUrl1 = "jdbc:sqlserver://my.no-ip.org:49159;databaseName=database;user=username;password=pw";
  4. Connection DbConn = null;
  5. Statement stmt = null;
  6. ResultSet rs = null;
  7.  
  8. Log.w("Success", "Class found.");
  9. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
  10.  
  11.  
  12. DbConn = DriverManager.getConnection(connectionUrl1);
  13. Log.w("Success", "Connection Established.");
  14.  
  15. stmt = DbConn.createStatement();
  16. rs = stmt.executeQuery("select * from table");
  17. DbConn.close();
  18.  
  19. } catch (SQLException sq) {
  20. displaymessage3.setText("Connection Errorn" + sq.getMessage());
  21. Log.w("Error connection", "" + sq.getMessage());
  22. } catch(Exception e){
  23. displaymessage4.setText("Connection Errorn" + e.getMessage());
  24. Log.w("Error connection", "" + e.getMessage());
  25. }
  26. }
  27.  
  28. 03-20 22:17:03.507 1830-1830/myprogram W/Success: Class found.
  29. 03-20 22:17:03.517 1830-1830/myprogram W/Error connection: null
  30.  
  31. var conn = Jdbc.getConnection('jdbc:sqlserver://my.no-ip.org:49159', 'username', 'pw');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement