I'm making a small program in Java that uses a Mysql connection but im getting some problems with the jdbc drivers. I installed Java EE and Java SE but i still get the message that there are no suitable driver for jdbc:mysql://localhost:3307/test
. Can someone explain to me what i am doing wrong.
Code:
public class Mysql_Connection_2 {
/**
* @param args the command line arguments
*/
static String query = "select count(*) from stock";
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
Logger.getLogger(MysqlConnection.class.getName()).log(Level.SEVERE, null, ex);
}
MysqlConnection.dbConnection(query);
}
}
Extern Connection class:
public class MysqlConnection {
private static final String dbURL = "jdbc:mysql://localhost:3307/test";
private static final String dbuname = "root";
private static final String dbpass = "usbw";
static Connection dbcon = null;
static Statement stmt = null;
static ResultSet rs = null;
public static void dbConnection (String query){
try{
//getting database connection to MySQL server
dbcon = DriverManager.getConnection(dbURL, dbuname, dbpass);
//getting PreparedStatment to execute query
stmt = dbcon.prepareStatement(query);
//Resultset returned by query
rs = stmt.executeQuery(query);
while(rs.next()) {
int count = rs.getInt(1);
System.out.println("count of stock : " + count);
}
}
catch(SQLException ex){
System.out.println(ex.getMessage());
}
}
}