Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SQLConnection[JDBC["Microsoft SQL Server(jTDS)", "localhost:1433/TestDatbase"],
- "Catalog" -> Automatic, "Description" -> None, "Name" -> "DemoSql",
- "Password" -> "test", "Properties" -> {}, "ReadOnly" -> False,
- "RelativePath" -> False, "TransactionIsolationLevel" -> "ReadUncommitted",
- "UseConnectionPool" -> False, "Username" -> "DemoLogin", "Version" -> 2.]
- Sever Name: xxxx7ezff6.database.windows.net
- User Name: xxxxxxxx
- password: password
- Database: AdventureWorks2012
- SQLConnection[JDBC["Microsoft SQL Server(jTDS)",
- "xxxx7ezff6.database.windows.net:1433/AdventureWorks2012"],
- "Catalog" -> Automatic, "Description" -> None, "Name" -> "AdvTest",
- "Password" -> "password", "Properties" -> {}, "ReadOnly" -> False,
- "RelativePath" -> False, "TransactionIsolationLevel" -> "ReadUncommitted",
- "UseConnectionPool" -> False, "Username" -> "xxxxxxxx", "Version" -> 2.]
- conn = OpenSQLConnection[
- JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-09/model"],
- "Username" -> "sa", "Password" -> "N3tC0nf1g"]
- SQLConnection[1, "Open", "Catalog" -> "model",
- "TransactionIsolationLevel" -> "ReadCommitted"]
- conn1 = OpenSQLConnection[
- JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-09/master"],
- "Username" -> "sa", "Password" -> "N3tC0nf1g"]
- SQLConnection[2, "Open", "Catalog" -> "master",
- "TransactionIsolationLevel" -> "ReadCommitted"]
- (*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.*)
- conn2 = OpenSQLConnection[JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-09"],
- "Username" -> "sa", "Password" -> "N3tC0nf1g"]
- SQLConnection[3, "Open", "Catalog" -> "master",
- "TransactionIsolationLevel" -> "ReadCommitted"]
- (*Look at the open connection to make sure.*)
- SQLConnections[]
- {SQLConnection[1, "Open", "Catalog" -> "model",
- "TransactionIsolationLevel" -> "ReadCommitted"],
- SQLConnection[2, "Open", "Catalog" -> "master",
- "TransactionIsolationLevel" -> "ReadCommitted"],
- SQLConnection[3, "Open", "Catalog" -> "master",
- "TransactionIsolationLevel" -> "ReadCommitted"]}
- (*Check what tables exist through the current connection*)
- SQLTables[conn]
- {}
- SQLTables[conn1]
- {SQLTable["MSreplication_options", "TableType" -> "TABLE"],
- SQLTable["spt_fallback_db", "TableType" -> "TABLE"],
- SQLTable["spt_fallback_dev", "TableType" -> "TABLE"],
- SQLTable["spt_fallback_usg", "TableType" -> "TABLE"],
- SQLTable["spt_monitor", "TableType" -> "TABLE"],
- SQLTable["spt_values", "TableType" -> "TABLE"]}
- SQLTables[conn2]
- {SQLTable["MSreplication_options", "TableType" -> "TABLE"],
- SQLTable["spt_fallback_db", "TableType" -> "TABLE"],
- SQLTable["spt_fallback_dev", "TableType" -> "TABLE"],
- SQLTable["spt_fallback_usg", "TableType" -> "TABLE"],
- SQLTable["spt_monitor", "TableType" -> "TABLE"],
- SQLTable["spt_values", "TableType" -> "TABLE"]}
- (*Check that I can access data from one of the tables in the connection using the SQL query approach*)
- SQLExecute[conn1, "SELECT * FROM MSreplication_options",
- "GetAsStrings" -> True] // InputForm
- {{"transactional", "1", "90", "0", "0", "0"}, {"merge", "1", "90", "0", "0", "0"}, {"security_model", "1", "90", "0", "0", "0"}}
- (*Try another server*)
- conn = OpenSQLConnection[
- JDBC["Microsoft SQL Server(jTDS)", "ECSDBN-SRV-04.enerserv.local"],
- "Username" -> "sa", "Password" -> "P@ssw0rd"]
- JDBC::error: Network error IOException: Connection refused: connect >>
- $Failed
- Reference material: DatabaseLink/tutorial/Overview
- conn=OpenSQLConnection[
- JDBC["Microsoft SQL Server(jTDS)", "185.50.123.132"],
- "Username" -> "myUser",
- "Password" -> "MyPass"
- ]
- Use this code :
- public class ConnectionClass {
- String ip = "192.168.0.131";
- String classs = "net.sourceforge.jtds.jdbc.Driver";
- String db = "Andro";
- String un = "sa";
- String password = "Admnsql";
- @SuppressLint("NewApi")
- public Connection CONN() {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
- .permitAll().build();
- StrictMode.setThreadPolicy(policy);
- Connection conn = null;
- String ConnURL = null;
- try {
- Class.forName(classs);
- ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
- + "databaseName=" + db + ";user=" + un + ";password="
- + password + ";";
- conn = DriverManager.getConnection(ConnURL);
- } catch (SQLException se) {
- Log.e("ERRO", se.getMessage());
- } catch (ClassNotFoundException e) {
- Log.e("ERRO", e.getMessage());
- } catch (Exception e) {
- Log.e("ERRO", e.getMessage());
- }
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement