java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/tun_recrut -
i'm new in java , i'm trying make simple authentication interface.
i trying execute simple query using drivermanager . can please me understand issue here ?
1/ mydbconnection.java
package com.esprit.tunrecrut.util; import java.sql.connection; import java.sql.drivermanager; import java.sql.sqlexception; import java.util.logging.level; import java.util.logging.logger; public class mydbconnection { /** * déclaration des variables pour la connexion */ private string url = "jdbc:mysql://localhost:3306/tun_recrut"; private string login = "root"; private string pwd = ""; private static mydbconnection instance; public static connection connection; private mydbconnection() { try { connection = drivermanager.getconnection(url,login,pwd); } catch (sqlexception ex) { logger.getlogger(mydbconnection.class.getname()).log(level.severe, null, ex); } } public static connection getconnection() { return connection; } public static mydbconnection getinstance() { if(instance==null) instance = new mydbconnection(); return instance; } }
2/crud.java
package com.esprit.tunrecrut.util; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.util.logging.level; import java.util.logging.logger; public class crud { mydbconnection mc = mydbconnection.getinstance(); public boolean execute(string sql){ try { statement statement = mc.getconnection().createstatement(); statement.executeupdate(sql); return true; } catch (sqlexception ex) { logger.getlogger(crud.class.getname()).log(level.severe, null, ex); return false; } } public resultset exeread(string sql){ try { statement statement = mc.getconnection().createstatement(); resultset rs; rs = statement.executequery(sql); return rs; } catch (sqlexception ex) { logger.getlogger(crud.class.getname()).log(level.severe, null, ex); return null; } } }
in userdao.java
public user finduserbyemailandpassword(string email, string password) { user user=null; try { string sql = "select * user email_address = '" + email + "' , password = '" + password + "'"; resultset rs = crud.exeread(sql); while (rs.next()) { user = new user(rs.getint("id"), rs.getstring("type"), rs.getstring("email_address")); } return user; } catch (sqlexception ex) { logger.getlogger("client controller").log(level.severe, " fail"); // logger.getlogger("client dao").log(level.severe, null, ex); return null; } }
you missing mysql-connector-java-x.x.x.jar on class path
Comments
Post a Comment