i'm trying connect mysql database using program below. depending on how present connection string following errors.
ip address separated 'mysql' ':' only: conn = drivermanager.getconnection("jdbc:mysql:[valid ip address]/localhost:3306/[valid database name]","[valid username]","[valid password]");
sqlstate: 08001 vendorerror: 0 java.sql.sqlexception: no suitable driver found jdbc:mysql:[valid ip address]/localhost:3306/[valid database name]
ip address separated 'mysql' ':http://': conn = drivermanager.getconnection("jdbc:mysql:http://[valid ip address]/localhost:3306/[valid database name]","[valid username]","[valid password]");
sqlstate: 08001 vendorerror: 0 java.sql.sqlexception: no suitable driver found jdbc:mysql:http://[valid ip address]/localhost:3306/[valid database name]
ip address separated 'mysql' '://': conn = drivermanager.getconnection("jdbc:mysql://[valid ip address]/localhost:3306/[valid database name]","[valid username]","[valid password]");
com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure last packet sent server 0 milliseconds ago. driver has not received packets server. sqlstate: 08s01 vendorerror: 0
in latter instance stacktrace provides 'caused by: java.net.connectexception: connection refused: connect'
in cases stacktrace indicates line of code setting variable 'conn' throwing exception.
note in program listing text within square brackets represents obfuscated code , brackets not in program.
my question is, have required drivers installed or not, or there problem connection string? there other issue haven't thought of?
code follows
package [package name]; import org.junit.test; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; public class sqlconnectiontest { @test public void startwebdriver() { try { class.forname("com.mysql.jdbc.driver").newinstance(); } catch (exception ex) { system.out.println(ex.getmessage()); } statement stmt = null; connection conn = null; resultset rs = null; try { conn = drivermanager.getconnection("jdbc:mysql://[valid ip address]/localhost:3306/[valid database name]","[valid username]","[valid password]"); // connection } catch (sqlexception ex) { // handle errors system.out.println("sqlstate: " + ex.getsqlstate()); system.out.println("vendorerror: " + ex.geterrorcode()); ex.printstacktrace(); } try { conn.close(); } catch (sqlexception e) { system.out.println(e.getmessage()); } } } some information on environment:
ide: eclipse luna service release 2 (4.4.2), build id: 20150219-0600
jre system library: jre1.8.0_45
mysqlconnector library: mysql-connector-java-5.1.36.jar (appears in referenced libraries section of package explorer)
i've installed mysql-connector-java-gpl-5.1.36, jdk-8u45-windows-x64 , selenium-java-2.45.0
i'll happy provide further information required.
the connection process seems ok me, there's strange in connection url. have
conn = drivermanager.getconnection("jdbc:mysql://[valid ip address]/localhost:3306/[valid database name]","[valid username]","[valid password]"); which has ip address , localhost:port. not valid url, yo have remove either localhost or ip address:
conn = drivermanager.getconnection("jdbc:mysql://[valid ip address]:3306/[valid database name]","[valid username]","[valid password]"); or
conn = drivermanager.getconnection("jdbc:mysql://localhost:3306/[valid database name]","[valid username]","[valid password]"); that should trick.
Comments
Post a Comment