i am creating simple crud system using android with mysql. but when I tried to add the data I got the errors. i attached image below. mysql driver i have put into the lib folder but i got the error.i attached the error below. i don't if i write code correct or not inorder to connect mysql and android if there is any thing wrong pls help me to correct
W/System.err: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.lang.Class.classForName(Native Method)
W/System.err: at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
W/System.err: at com.example.kobinath.mylcrud.MainActivity$Send.doInBackground(MainActivity.java:61)
at com.example.kobinath.mylcrud.MainActivity$Send.doInBackground(MainActivity.java:41)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
W/System.err: 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.NoClassDefFoundError: com/mysql/jdbc/Driver
MainActivity.java
public class MainActivity extends AppCompatActivity {
EditText ed1,ed2;
Button b1,b2;
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.title);
ed2 = findViewById(R.id.course);
b1 = findViewById(R.id.btn1);
b2 = findViewById(R.id.v1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Send objsend = new Send();
objsend.execute("");
}
});
}
private class Send extends AsyncTask<String, String,String> {
String title = ed1.getText().toString();
String description = ed2.getText().toString();
@Override
protected String doInBackground(String... strings) {
String url = "jdbc:mysql//192.168.84.2/sdl";
String user = "root";
String pass = "";
Connection conn = null;
String ConnURL;
{
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
if(con == null)
{
Toast.makeText(getApplicationContext(),"fail",Toast.LENGTH_LONG).show();
}
else
{
PreparedStatement pst;
pst = conn.prepareStatement("insert into records(course,fee)values(?,?)");
pst.setString(1, title);
pst.setString(2, description);
pst.executeUpdate();
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
ed1.setText("");
ed2.setText("");
ed1.requestFocus();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
return url;
}
build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
implementation('libs/mysql-connector-java-5.1.47-bin.jar')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}