I am using jdbc mysql connector to connect my android studio project with XAMPP. After I compile my program and proceed with filling the information in my app , I click the button and it throws this error.
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mydatabase
W/System.err: at java.sql.DriverManager.getConnection(DriverManager.java:605)
at java.sql.DriverManager.getConnection(DriverManager.java:218)
at com.example.myproject.views.CartFragment$3.onClick(CartFragment.java:132)
at android.view.View.performClick(View.java:7448)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
This is my implementation if the database connection. I have successfully implemented the .jar jdbc connector in my app/libs directory as a library module. YES, I have tried the Class.forName("com.mysql.jdbc.Driver") but it throws yet another error, so that was not an option. I read that after JAVA 5 calling the Class.forName was not required.
Initially I used Connection, Statement but it throws the same error as of when I use JdbcConnection and JdbcStatement.
try {
String url = "jdbc:mysql://localhost:3306/mydatabase";
String username = "root";
String password = "";
JdbcConnection con = (JdbcConnection) DriverManager.getConnection(url,username,password);
JdbcStatement st = (JdbcStatement) con.createStatement();
st.addBatch(query);
st.addBatch(query2);
st.executeBatch();
}
catch (SQLException throwables) {
throwables.printStackTrace();
}
Dependencies on my build.gradle:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/mysql-connector-java-8.0.23')
Class.forName("com.mysql.jdbc.Driver");- Pandey Amit