java - trying to connect to mysql database -
i'm trying connect database. added mysql connector driver jar
- creating folder called lib
- putting jar inside lib
- right clicking on project >> properties >> build path >> (going inside libraries tab) >> adding jar
my code looks this:
public static void main(string[] args) { try { connection myconn = drivermanager.getconnection("jdbc:mysql://localhost:3306/world", "user", "pass"); statement mystat = myconn.createstatement(); resultset myrs = mystat.executequery("select * city"); while (myrs.next()) { system.out.println(myrs.getstring("name")); } } catch (exception exc) { exc.printstacktrace(); }}
error:
java.sql.sqlexception: no suitable driver found jdbc:mysql://localhost:3306/world @ java.sql.drivermanager.getconnection(unknown source) @ java.sql.drivermanager.getconnection(unknown source) @ javademo4.driver.main(driver.java:8)
i'm using eclipse luna , mysql-connector-java-5.0.8-bin.jar. have database called world , table called city has column called name
first of have register mysql driver, add line above connection
line class.forname("com.mysql.jdbc.driver")
hope helps
Comments
Post a Comment