Click here to Skip to main content
14,919,811 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to connect and login to MS SQL database 2012 on smartasp.net hosting. I use the jtds-1.3.1 to connect to the database 2012. But the connection does not work and this is error appears:
java.lang.RuntimeException: An error occured while executing doInBackground()
                                                                          at android.os.AsyncTask$3.done(AsyncTask.java:278)
                                                                          at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
                                                                          at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
                                                                          at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
                                                                          at java.util.concurrent.FutureTask.run(FutureTask.java:137)
                                                                          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
                                                                          at java.lang.Thread.run(Thread.java:856)
                                                                       Caused by: java.lang.VerifyError: net/sourceforge/jtds/jdbc/TdsCore
                                                                          at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:359)
                                                                          at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
                                                                          at java.sql.DriverManager.getConnection(DriverManager.java:175)
                                                                          at java.sql.DriverManager.getConnection(DriverManager.java:140)
                                                                          at com.example.kamran.login.MainActivity.connectionclass(MainActivity.java:158)
                                                                          at com.example.kamran.login.MainActivity$CheckLogin.doInBackground(MainActivity.java:106)
                                                                          at com.example.kamran.login.MainActivity$CheckLogin.doInBackground(MainActivity.java:73)
                                                                          at android.os.AsyncTask$2.call(AsyncTask.java:264)

my Main_activity:
public class MainActivity extends AppCompatActivity
{
// Declaring layout button, edit texts
Button login;
EditText username,password,lable;
ProgressBar progressBar;
// End Declaring layout button, edit texts

// Declaring connection variables
Connection con;
String un,pass,db,ip;
String usernam,passwordd;
//End Declaring connection variables

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting values from button, texts and progress bar
    login = (Button) findViewById(R.id.button);
    username = (EditText) findViewById(R.id.editText);
    password = (EditText) findViewById(R.id.editText2);
    lable = (EditText) findViewById(R.id.editText3);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressBar.setVisibility(View.GONE);
    // End Getting values from button, texts and progress bar

    // Declaring Server ip, username, database name and password
    ip = "SQL7002";
    db = "????????";
    un = "????????";
    pass = "??????";
    // Declaring Server ip, username, database name and password


    // Setting up the function when button login is clicked
    login.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            usernam = username.getText().toString();
            passwordd = password.getText().toString();
            CheckLogin checkLogin = new CheckLogin();// this is the 
Asynctask, which is used to process in background to reduce load on app 
process
            checkLogin.execute("");
        }
    });
    //End Setting up the function when button login is clicked
}

public class CheckLogin extends AsyncTask<String,String,String>
{
    String z = "";
    Boolean isSuccess = false;

    @Override
    protected void onPreExecute()

    {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onPostExecute(String r)
    {
        progressBar.setVisibility(View.GONE);
        Toast.makeText(MainActivity.this, r, Toast.LENGTH_SHORT).show();
        if(isSuccess)
        {
            Toast.makeText(MainActivity.this , "Login Successfull" , Toast.LENGTH_LONG).show();
            //finish();
        }
    }
    @Override
    protected String doInBackground(String... params)
    {

        if(usernam.trim().equals("")|| passwordd.trim().equals(""))
            z = "Please enter Username and Password";
        else
        {
            try
            {
                con = connectionclass(un, pass, db, ip);        // Connect to database
                if (con == null)
                {
                    z = "Check Your Internet Access!";
                }
                else
                {
                    final String query = "select Spec from Password where Num= '" + usernam.toString() + "' and Pass = '"+ passwordd.toString() +"' ";
                    Statement stmt = con.createStatement();
                    ResultSet rs = stmt.executeQuery(query);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            lable.setText(query);
                        }
                    });
                    if(rs.next())
                    {

                        z = "Login successful";
                        isSuccess=true;
                        con.close();
                    }
                    else
                    {
                        z = "Invalid Credentials!";
                        isSuccess = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isSuccess = false;
                z = ex.getMessage();
            }
        }
        return z;
    }
}


@SuppressLint("NewApi")
public Connection connectionclass(String un, String pass, String db, String ip)
{
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    java.sql.Connection connection = null;
    String ConnectionURL = null;
    try
    {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        ConnectionURL = "jdbc:jtds:sqlserver://SQL7002.site4now.net;database=?????????;user=?????????;password=???????????";
        connection = DriverManager.getConnection(ConnectionURL);
    }
    catch (SQLException se)
    {
        Log.e("error here 1 : ", se.getMessage());
    }
    catch (ClassNotFoundException e)
    {
        Log.e("error here 2 : ", e.getMessage());
    }
    catch (Exception e)
    {
        Log.e("error here 3 : ", e.getMessage());
    }
    return connection;
}
}


What I have tried:

Upload the database again and modify connection string.
Posted
Comments
CHill60 11-Jun-18 9:48am
   
Next time don't just repost your question (see How to login to SQL online database android[^]) - Use the "Improve question" link to add the extra detail to your question
David Crow 11-Jun-18 15:57pm
   
ip = "SQL7002";
db = "????????";
un = "????????";
pass = "??????";
...
con = connectionclass(un, pass, db, ip);        // Connect to database


You appear to be passing invalid parameters to connectionclass(). Is that intentional?
Member 13366692 12-Jun-18 3:56am
   
question mark ? This is used to hide my username and password ..
Darren_vms 14-Jun-18 15:02pm
   
It looks like the issue is caused by jtds, try using jtds-1.3.0 just to see if the problem is resolved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900