Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.annotation.SuppressLint;
- import android.os.StrictMode;
- import android.util.Log;
- import java.sql.SQLException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- public class ConnectionClass {
- String ip = "IP_Address(for eg.192.168.5.60)";
- String classs = "net.sourceforge.jtds.jdbc.Driver";
- String db = "Andro";
- String un = "username";
- String password = "pwd";
- @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 + ";";*/
- ConnURL= "jdbc:jtds:sqlserver://IP_Address(for eg.192.168.5.60)/databaseName=Andro;user=username;password=pwd;";
- 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;
- }
- }
- @Override
- protected String doInBackground(String... params) {
- if(userid.trim().equals("")|| password.trim().equals(""))
- z = "Please enter User Id and Password";
- else
- {
- try {
- Connection con = connectionClass.CONN();
- if (con == null) {
- z = "Error in connection with SQL server";
- } else {
- heading.setText("u"+con.toString());
- String query = "select * from Usertbl where UserId='" + userid + "' and Password='" + password + "'";
- Statement stmt = con.createStatement();
- heading.setText("After statement");
- ResultSet rs = stmt.executeQuery(query);
- // heading.setText(rs.getString(1));
- z = "under else block";
- if(rs.next())
- {
- z = "Login successfull";
- isSuccess=true;
- }
- else
- {
- z = "Invalid Credentials";
- isSuccess = false;
- }
- }
- }
- catch (Exception ex)
- {
- isSuccess = false;
- z = "Exceptions";
- }
- }
- return z;
- }
Add Comment
Please, Sign In to add comment