jdbc connection problem

Quickly share your Android Code Snippets here...

jdbc connection problem

Postby krishnaveni » Thu Feb 16, 2012 2:11 pm

HI i developed one login form..here am getting some error in logcat.the error is:
02-16 18:35:44.790: E/LoginLayoutActivity(617): null
02-16 18:35:44.790: E/LoginLayoutActivity(617): java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.SocketException: java.net.SocketException: The operation timed out
02-16 18:35:44.790: E/LoginLayoutActivity(617): ** BEGIN NESTED EXCEPTION **
02-16 18:35:44.790: E/LoginLayoutActivity(617): java.net.SocketException
02-16 18:35:44.790: E/LoginLayoutActivity(617): MESSAGE: java.net.SocketException: The operation timed out
02-16 18:35:44.790: E/LoginLayoutActivity(617): STACKTRACE:
02-16 18:35:44.790: E/LoginLayoutActivity(617): java.net.SocketException: java.net.SocketException: The operation timed out
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.Connection.<init>(Connection.java:452)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.sql.DriverManager.getConnection(DriverManager.java:191)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.sql.DriverManager.getConnection(DriverManager.java:226)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.example.login.LoginLayoutActivity$1.onClick(LoginLayoutActivity.java:60)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.view.View.performClick(View.java:2408)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.view.View$PerformClick.run(View.java:8816)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.os.Handler.handleCallback(Handler.java:587)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.os.Handler.dispatchMessage(Handler.java:92)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.os.Looper.loop(Looper.java:123)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.lang.reflect.Method.invoke(Method.java:521)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at dalvik.system.NativeStart.main(Native Method)
02-16 18:35:44.790: E/LoginLayoutActivity(617): ** END NESTED EXCEPTION **
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.Connection.createNewIO(Connection.java:1875)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.Connection.<init>(Connection.java:452)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.sql.DriverManager.getConnection(DriverManager.java:191)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.sql.DriverManager.getConnection(DriverManager.java:226)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.example.login.LoginLayoutActivity$1.onClick(LoginLayoutActivity.java:60)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.view.View.performClick(View.java:2408)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.view.View$PerformClick.run(View.java:8816)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.os.Handler.handleCallback(Handler.java:587)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.os.Handler.dispatchMessage(Handler.java:92)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.os.Looper.loop(Looper.java:123)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.lang.reflect.Method.invokeNative(Native Method)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at java.lang.reflect.Method.invoke(Method.java:521)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-16 18:35:44.790: E/LoginLayoutActivity(617): at dalvik.system.NativeStart.main(Native Method)
dis is my loginactivity.java file
Code: Select all
package com.example.login;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginLayoutActivity extends Activity {
   
   String user;
   EditText username,password;
   TextView error;
    Button ok;
   
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        username=(EditText)findViewById(R.id.et_un);
        password=(EditText)findViewById(R.id.et_pw);
       
        ok=(Button)findViewById(R.id.btn_login);
     
        ok.setOnClickListener(new View.OnClickListener() {

           

         @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            
            user = username.getText().toString();
            String pass = password.getText().toString();
            
               try {
                  
                  Class.forName("com.mysql.jdbc.Driver");
               }
               catch (ClassNotFoundException ex) {
                    Logger.getLogger(LoginLayoutActivity.class.getName()).log(Level.SEVERE, null, ex);
                }
               
               
                  try {
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost/ari", "root", "");
                        Statement st = con.createStatement();
                     
                      
                        ResultSet rs = st.executeQuery("SELECT password FROM customers where username='"+user+"'");
         
                        if(rs.next())
                        {
                            String dbpass = rs.getString(1);
                            if(dbpass.equals(pass)){
                                error.setText("Correct Username or Password");
                                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.co.in"));
                                startActivity(i);
                        }
                        else
                        {
                           error.setText("Sorry!! Incorrect Username or Password");
                        }
                       }
                       
                    } catch (Exception ex) {
                        Logger.getLogger(LoginLayoutActivity.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
           
           
        });
    }
}

why dis error is occurred here.plz give me some solutions...
krishnaveni
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Dec 21, 2011 6:23 am

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 6 guests