SHARE
TWEET

Untitled

a guest Mar 20th, 2016 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top