Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. SQLConnection[JDBC["Microsoft SQL Server(jTDS)", "localhost:1433/TestDatbase"],
  2. "Catalog" -> Automatic, "Description" -> None, "Name" -> "DemoSql",
  3. "Password" -> "test", "Properties" -> {}, "ReadOnly" -> False,
  4. "RelativePath" -> False, "TransactionIsolationLevel" -> "ReadUncommitted",
  5. "UseConnectionPool" -> False, "Username" -> "DemoLogin", "Version" -> 2.]
  6.  
  7. Sever Name: xxxx7ezff6.database.windows.net
  8. User Name: xxxxxxxx
  9. password: password
  10. Database: AdventureWorks2012
  11.  
  12. SQLConnection[JDBC["Microsoft SQL Server(jTDS)",
  13. "xxxx7ezff6.database.windows.net:1433/AdventureWorks2012"],
  14. "Catalog" -> Automatic, "Description" -> None, "Name" -> "AdvTest",
  15. "Password" -> "password", "Properties" -> {}, "ReadOnly" -> False,
  16. "RelativePath" -> False, "TransactionIsolationLevel" -> "ReadUncommitted",
  17. "UseConnectionPool" -> False, "Username" -> "xxxxxxxx", "Version" -> 2.]
  18.  
  19. conn = OpenSQLConnection[
  20. JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-09/model"],
  21. "Username" -> "sa", "Password" -> "N3tC0nf1g"]
  22.  
  23. SQLConnection[1, "Open", "Catalog" -> "model",
  24. "TransactionIsolationLevel" -> "ReadCommitted"]
  25.  
  26. conn1 = OpenSQLConnection[
  27. JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-09/master"],
  28. "Username" -> "sa", "Password" -> "N3tC0nf1g"]
  29.  
  30. SQLConnection[2, "Open", "Catalog" -> "master",
  31. "TransactionIsolationLevel" -> "ReadCommitted"]
  32.  
  33. (*Here I have not specified the database nane after the server name and it just seems to pick the one on the top of the database list.*)
  34.  
  35. conn2 = OpenSQLConnection[JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-09"],
  36. "Username" -> "sa", "Password" -> "N3tC0nf1g"]
  37.  
  38. SQLConnection[3, "Open", "Catalog" -> "master",
  39. "TransactionIsolationLevel" -> "ReadCommitted"]
  40.  
  41. (*Look at the open connection to make sure.*)
  42.  
  43. SQLConnections[]
  44.  
  45. {SQLConnection[1, "Open", "Catalog" -> "model",
  46. "TransactionIsolationLevel" -> "ReadCommitted"],
  47. SQLConnection[2, "Open", "Catalog" -> "master",
  48. "TransactionIsolationLevel" -> "ReadCommitted"],
  49. SQLConnection[3, "Open", "Catalog" -> "master",
  50. "TransactionIsolationLevel" -> "ReadCommitted"]}
  51.  
  52. (*Check what tables exist through the current connection*)
  53.  
  54. SQLTables[conn]
  55.  
  56. {}
  57.  
  58. SQLTables[conn1]
  59.  
  60. {SQLTable["MSreplication_options", "TableType" -> "TABLE"],
  61. SQLTable["spt_fallback_db", "TableType" -> "TABLE"],
  62. SQLTable["spt_fallback_dev", "TableType" -> "TABLE"],
  63. SQLTable["spt_fallback_usg", "TableType" -> "TABLE"],
  64. SQLTable["spt_monitor", "TableType" -> "TABLE"],
  65. SQLTable["spt_values", "TableType" -> "TABLE"]}
  66.  
  67. SQLTables[conn2]
  68.  
  69. {SQLTable["MSreplication_options", "TableType" -> "TABLE"],
  70. SQLTable["spt_fallback_db", "TableType" -> "TABLE"],
  71. SQLTable["spt_fallback_dev", "TableType" -> "TABLE"],
  72. SQLTable["spt_fallback_usg", "TableType" -> "TABLE"],
  73. SQLTable["spt_monitor", "TableType" -> "TABLE"],
  74. SQLTable["spt_values", "TableType" -> "TABLE"]}
  75.  
  76. (*Check that I can access data from one of the tables in the connection using the SQL query approach*)
  77.  
  78. SQLExecute[conn1, "SELECT * FROM MSreplication_options",
  79. "GetAsStrings" -> True] // InputForm
  80.  
  81. {{"transactional", "1", "90", "0", "0", "0"}, {"merge", "1", "90", "0", "0", "0"}, {"security_model", "1", "90", "0", "0", "0"}}
  82.  
  83. (*Try another server*)
  84.  
  85. conn = OpenSQLConnection[
  86. JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-04.enerserv.local"],
  87. "Username" -> "sa", "Password" -> "P@ssw0rd"]
  88.  
  89. JDBC::error: Network error IOException: Connection refused: connect >>
  90.  
  91. $Failed
  92.  
  93. Reference material: DatabaseLink/tutorial/Overview
  94.  
  95. conn=OpenSQLConnection[
  96. JDBC["Microsoft SQL Server(jTDS)", "185.50.123.132"],
  97. "Username" -> "myUser",
  98. "Password" -> "MyPass"
  99. ]
  100.  
  101. Use this code :
  102.  
  103. public class ConnectionClass {
  104. String ip = "192.168.0.131";
  105. String classs = "net.sourceforge.jtds.jdbc.Driver";
  106. String db = "Andro";
  107. String un = "sa";
  108. String password = "Admnsql";
  109. @SuppressLint("NewApi")
  110. public Connection CONN() {
  111. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
  112. .permitAll().build();
  113. StrictMode.setThreadPolicy(policy);
  114. Connection conn = null;
  115. String ConnURL = null;
  116. try {
  117. Class.forName(classs);
  118. ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
  119. + "databaseName=" + db + ";user=" + un + ";password="
  120. + password + ";";
  121. conn = DriverManager.getConnection(ConnURL);
  122. } catch (SQLException se) {
  123. Log.e("ERRO", se.getMessage());
  124. } catch (ClassNotFoundException e) {
  125. Log.e("ERRO", e.getMessage());
  126. } catch (Exception e) {
  127. Log.e("ERRO", e.getMessage());
  128. }
  129. return conn;
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement