gpt4 book ai didi

java.sql.jdbc.SQLException : No suitable driver on when connect to XAMPP MYSQL 异常

转载 作者:行者123 更新时间:2023-11-30 22:05:25 25 4
gpt4 key购买 nike

<分区>

有人可以帮助我吗?当我点击登录按钮时,我总是会遇到这种异常,如下图所示:

enter image description here

MainActivity 的这段代码:

package com.TPK.SistemPendataanPelalatan;


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

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;



public class MainActivity extends Activity {

TextView ket;
EditText id_user,pass;
Button btnlogin;



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

//deklarasi input dan output

ket =(TextView) findViewById(R.id.warning_login);
id_user = (EditText) findViewById(R.id.singup_id);
pass = (EditText) findViewById(R.id.input_pass);
btnlogin = (Button) findViewById(R.id.login);


// event tombol ditekan
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String id=id_user.getText().toString();
String pw=pass.getText().toString();

int salah=0;//hitung jumlah kesalahan
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {

Statement st=(Statement)hubung.GetConnection().createStatement();

if(id_user.getText().toString().isEmpty()||pass.getText().toString().isEmpty()){
ket.setText("ID dan Password Harus di Isi!");
}else{
ResultSet rs=st.executeQuery("select * from user where id='"+id+"'and password='"+pw+"'");
if(rs.next()){
//kalo sukses masuk
ket.setText("Selamat Datang ...");
String nama=rs.getString(1);
if(rs.getString(5)=="1"){//ADMIN
Intent i = new Intent(MainActivity.this, activity_user_admin.class);
i.putExtra("nama", nama);//passing nama ke activity user admin
startActivity(i);
st.close();
}else if(rs.getString(5)=="2"){//SUPERVISOR
Intent i = new Intent(MainActivity.this, activity_user_super.class);
i.putExtra("nama", nama);//passing nama ke activity user super
startActivity(i);
st.close();
}else if(rs.getString(5)=="3"){//TEKNISI
Intent i = new Intent(MainActivity.this, activity_user_teknisi.class);
i.putExtra("nama", nama);//passing nama ke activity user teknisi
startActivity(i);
st.close();
}
}
else {
ket.setText("ID atau Password Salah !");
salah++;
if(salah>3){
salah=0;
ket.setText("Silahkan Lapor Admin");
}

}
}

} catch (SQLException e) {
// TODO Auto-generated catch block
ket.setText(e.toString());
}
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

}

这是我调用 jdbc 以名称 hubung 连接到 mysql 的地方:

package com.TPK.SistemPendataanPelalatan;
import java.sql.*;

public class hubung {
private static Connection kon;
public static Connection GetConnection() throws SQLException{
if(kon==null){
kon = DriverManager.getConnection("jdbc:mysql://10.11.1.232:3306/tpk_peralatan","root","");
}
return kon;

}
}

谢谢...

注意:这个程序可以正常构建和运行,但卡在 mysql 连接中......

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com