Can't connect to mysql database java -


this question has answer here:

i'm trying connect msql database, keep getting error: no suitable driver found jdbc:mysql://localhost:3306/test3.

try{       connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/test3" , "root", "julius");          statement statement = (statement) con.createstatement();          string insert = "insert testtable value ('guy' , '0156421";          statement.executeupdate(insert);      }catch(exception e){      system.out.println("error: " + e.getmessage());      } 

i have not installed mysql connector, since import java.sql.connection;, java.sql.drivermanager;, java.sql.statement; guess wasn't needed.

you have register jdbc driver before creating connection. in case mysql driver. download mysql-connector jar , add classpath , run application below code

try{   //register jdbc driver   class.forname("com.mysql.jdbc.driver");    //open connection   connection conn = drivermanager.getconnection(db_url,user,pass);    //create statement   statement stmt = conn.createstatement();    //execute query   string insert = "insert testtable value ('guy' , '0156421')";   stmt.executeupdate(insert); } catch(exception e){   system.out.println("exception " + e.getmessage()); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -