Guest User

Untitled

a guest
Oct 23rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. setContentView(R.layout.activity_flux_sequence);
  4.  
  5. String url = "jdbc:jtdc:sqlserver://vps342074.ovh.net/IZY309";
  6. //String url = "jdbc:jtdc:sqlserver://vps342074.ovh.net/MSSQLSERVER;databaseName=IZY309";
  7. //String url = "jdbc:sqlserver://vps342074.ovh.net\MSSQLSERVER;databaseName=IZY309";
  8. String user = "x";
  9. String pass = "y";
  10.  
  11. try {
  12. //TextView textViewToChange = (TextView) findViewById(R.id.textViewCol5);
  13. //textViewToChange.setText("Hello");
  14. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  15. Connection con = DriverManager.getConnection(url, user, pass);
  16.  
  17. Statement statement = con.createStatement();
  18. ResultSet resultat = statement.executeQuery("SELECT CATEGORIE FROM dbo.PPROFIL WHERE CATEGORIE = 'ac' ");
  19. while (resultat.next()) {
  20.  
  21. String result = resultat.getString(1);
  22. TextView textViewToChange = (TextView) findViewById(R.id.textViewCol5);
  23. textViewToChange.setText(result);
  24. Log.d("My Custom Tag", result);
  25.  
  26.  
  27. }resultat.close();
  28. statement.close();
  29. } catch (SQLException e) {
  30. // TODO Auto-generated catch block
  31. e.printStackTrace();
  32. } catch (ClassNotFoundException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. private static void close(Connection con) {
  38. // TODO Auto-generated method stub
  39. close(con);
  40.  
  41. }
  42.  
  43. W/System.err: java.sql.SQLException: No suitable driver
  44. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:186)
  45. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:213)
  46. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at
  47. com.example.gaetan.fluxsequence.flux_sequence.onCreate(flux_sequence.java:32)
  48. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.Activity.performCreate(Activity.java:6876)
  49. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
  50. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
  51. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
  52. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.ActivityThread.access$1100(ActivityThread.java:222)
  53. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
  54. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
  55. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.os.Looper.loop(Looper.java:158)
  56. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7229)
  57. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at java.lang.reflect.Method.invoke(Native Method)
  58. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  59. 02-15 14:34:01.896 4180-4180/com.example.gaetan.fluxsequence W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  60.  
  61. String url = "jdbc:jtdc:sqlserver://vps342074.ovh.net/IZY309";
  62. try {
  63. //TextView textViewToChange = (TextView) findViewById(R.id.textViewCol5);
  64. //textViewToChange.setText("Hello");
  65. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  66.  
  67. Connection con = DriverManager.getConnection(url, user, pass);
  68.  
  69. Statement statement = con.createStatement();
  70. ResultSet resultat = statement.executeQuery("SELECT CATEGORIE FROM dbo.PPROFIL WHERE CATEGORIE = 'ac' ");
  71. while (resultat.next()) {
  72.  
  73. String result = resultat.getString(1);
  74. TextView textViewToChange = (TextView) findViewById(R.id.textViewCol5);
  75. textViewToChange.setText(result);
  76. Log.d("My Custom Tag", result);
  77. }
  78. resultat.close();
  79. statement.close();
  80.  
  81. } catch (SQLException e) {
  82. // TODO Auto-generated catch block
  83. e.printStackTrace();
  84. }
  85.  
  86. Before you make connection, you must add 2 line code:
  87. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  88. StrictMode.setThreadPolicy(policy);
  89. Complete code as: (may be)
  90. package com.ipvsoft.sendsms.utility;
  91.  
  92. import android.os.StrictMode;
  93. import android.util.Log;
  94.  
  95. import java.sql.Connection;
  96. import java.sql.DriverManager;
  97. import java.sql.SQLException;
  98.  
  99.  
  100. public class SQLConnection {
  101. private static final String LOG = "DEBUG";
  102. private static String ip = "192.168.3.85";
  103. private static String port = "1433";
  104. private static String classs = "net.sourceforge.jtds.jdbc.Driver";
  105. private static String db = "THTData";
  106. private static String un = "sa";
  107. private static String password = "admin";
  108. public static Connection connect() {
  109. Connection conn = null;
  110. String ConnURL = null;
  111. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  112. StrictMode.setThreadPolicy(policy);
  113. try {
  114. Class.forName(classs);
  115. ConnURL = "jdbc:jtds:sqlserver://" + ip +":"+port+";"
  116. + "databaseName=" + db + ";user=" + un + ";password="
  117. + password + ";";
  118. conn = DriverManager.getConnection(ConnURL);
  119. } catch (SQLException e) {
  120. Log.d(LOG, e.getMessage());
  121. } catch (ClassNotFoundException e) {
  122. Log.d(LOG, e.getMessage());
  123. }
  124. return conn;
  125. }
  126. }
Add Comment
Please, Sign In to add comment