android studio+javajdbc(未找到合适的驱动程序,并显示许多其他错误)

pvcm50d1  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(434)

在使用当前使用mamp的本地服务器测试登录窗体时,我在尝试执行登录测试时总是遇到以下错误:

W/System.err: java.sql.SQLException: No suitable driver found for jbdc:mysql://localhost/phpMyAdmin/diplomanya
    W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:605)
    W/System.err:     at java.sql.DriverManager.getConnection(DriverManager.java:218)
            at fr.ibra_yous.diplomany_v00001.ConnectBdd.ConnexionSQLBdd(ConnectBdd.java:20)
            at fr.ibra_yous.diplomany_v00001.Log_in.Connect(Log_in.java:57)
            at fr.ibra_yous.diplomany_v00001.Log_in.access$000(Log_in.java:15)
            at fr.ibra_yous.diplomany_v00001.Log_in$1.onClick(Log_in.java:34)
            at android.view.View.performClick(View.java:7448)
            at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
            at android.view.View.performClickInternal(View.java:7425)
            at android.view.View.access$3600(View.java:810)
            at android.view.View$PerformClick.run(View.java:28305)
    W/System.err:     at android.os.Handler.handleCallback(Handler.java:938)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:223)
            at android.app.ActivityThread.main(ActivityThread.java:7656)
            at java.lang.reflect.Method.invoke(Native Method)
    W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
    W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.ResultSet java.sql.Statement.executeQuery(java.lang.String)' on a null object reference
    W/System.err:     at fr.ibra_yous.diplomany_v00001.Log_in.Connect(Log_in.java:61)
            at fr.ibra_yous.diplomany_v00001.Log_in.access$000(Log_in.java:15)
            at fr.ibra_yous.diplomany_v00001.Log_in$1.onClick(Log_in.java:34)
            at android.view.View.performClick(View.java:7448)
            at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
            at android.view.View.performClickInternal(View.java:7425)
            at android.view.View.access$3600(View.java:810)
    W/System.err:     at android.view.View$PerformClick.run(View.java:28305)
            at android.os.Handler.handleCallback(Handler.java:938)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:223)
            at android.app.ActivityThread.main(ActivityThread.java:7656)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

我对android studio和java是新手,因此我对它们的含义没有任何线索,所以我想请求一些帮助,这样我就可以理解,而不是重犯导致我出现这些错误的错误,因为我将不得不制作一个注册表。
我不知道我是否应该把所有相关的代码联合起来,这些代码是logu不活动的,它包含了我的logu格式,清单文件,我添加了这一行:

`<uses-permission android:name="android.permission.INTERNET" />`

下面是允许连接到dbb的类代码:

import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;

    public class ConnectBdd {

        public static String Driverjbdc = "com.mysql.cj.jdbc.Driver";
        public static String url = "jbdc:mysql://localhost/phpMyAdmin/diplomanya";
        public static String password = "root";
        public static String user = "root";

        public static Statement ConnexionSQLBdd() {

            try {
                Class.forName(Driverjbdc);
                Connection conn = DriverManager.getConnection(url, user, password);
                Statement stmt = conn.createStatement();
                return stmt;

            } catch(SQLException e){
                e.printStackTrace();
                return null;

            } catch(Exception e){
                e.printStackTrace();
                return null;
            }

        }
    }
    ``` 
    The log in code : 
    ``` 
    import androidx.appcompat.app.AppCompatActivity;

    import android.content.Intent;
    import android.os.Bundle;
    import android.os.StrictMode;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    import java.sql.ResultSet;
    import java.sql.Statement;

    public class Log_in extends AppCompatActivity {

        private EditText inIdInput , inPasswordInput;
        private Button logButton , singInBtn;

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

            inIdInput = this.findViewById(R.id.id_champ);
            inPasswordInput = this.findViewById(R.id.id_pass_champ);
            logButton = this.findViewById(R.id.id_log_button);
            singInBtn = this.findViewById(R.id.id_singIn_button);

            logButton.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    Connect();
                }
            });

            singInBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent singInActivityIntent = new Intent(Log_in.this,
                            Sing_in.class );
                    startActivity(singInActivityIntent);
                }
            });

            if (android.os.Build.VERSION.SDK_INT > 9 ){
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }

        }

        private void Connect() {
            try{
                ConnectBdd connBdd = new ConnectBdd();
                Statement stmt = connBdd.ConnexionSQLBdd();

                String Request = "SELECT password_user FROM users WHERE mail_user = "+inIdInput.getText().toString()+"";

                final ResultSet rs = stmt.executeQuery(Request);
                if (rs.getString(1).equals(inPasswordInput.getText().toString())){
                    NextActivity();
                }

            }catch(Exception e){
                e.printStackTrace();
            }
        }

        private void NextActivity() {
            Intent redirect = new Intent(Log_in.this, MainActivity.class);
            startActivity(redirect);
            finish();
        }
    }
    ``` 

I really need help. Thank you.
kyxcudwk

kyxcudwk1#

原因是 SQLException 你会发现jdbc并不是为移动设备开发和设计的。不幸的是 Android 甚至没有一个 MYSQL JDBC driver .

相关问题