java - GWT and SQL - No Suitable Driver -
i'm having strange problem gwt , sql.
i'm trying gwt program communicate sql server. took several examples web , terminate following error:
severe: no suitable driver found jdbc:mysql://localhost:3306/table java.sql.sqlexception: no suitable driver found jdbc:mysql://localhost:3306/table
after racking brain hours , hours, came following code does work. running following happily output mysql version console:
public static void printversion() { connection con = null; statement st = null; resultset rs = null; string url = "jdbc:mysql://localhost:3306/table"; string user = "username"; string password = "password"; try { con = drivermanager.getconnection(url, user, password); st = con.createstatement(); rs = st.executequery("select version()"); if (rs.next()) { system.out.println(rs.getstring(1)); } } catch (sqlexception ex) { logger lgr = logger.getlogger(version.class.getname()); lgr.log(level.severe, ex.getmessage(), ex); } { try { if (rs != null) { rs.close(); } if (st != null) { st.close(); } if (con != null) { con.close(); } } catch (sqlexception ex) { logger lgr = logger.getlogger(version.class.getname()); lgr.log(level.warning, ex.getmessage(), ex); } } }
however, changed method outputting string console returning string calling function, started getting "no suitable driver found" error again.
the change made extremely subtle; here diff:
1c1 < public static string getversion() { --- > public static void printversion() { 10d9 < string rtn = null; 18c17 < rtn = rs.getstring(1); --- > system.out.println(rs.getstring(1)); 42d40 < return rtn;
the calling function changed version.printversion()
string str = version.getversion()
.
i'm experienced in php , making jump gwt/java. searched on , haven't been able find out why isn't working should. numerous tutorials , pre-existing code have failed me, i'm asking here.
i do have mysql jdbc driver in classpath, , have tried several permutations loading class.forname("com.mysql.jdbc.driver").newinstance();
, no avail
i'm sure i'm missing stupid, i'm inexperienced have clue what.
i don't know why class.forname("com.mysql.jdbc.driver").newinstance();
wasn't working before. tried several methods , none of them worked. (i have since deleted non-working work, can't compare why didn't work) did try in example though , appear work when added. here diff:
1c1 < public static string getversion() { --- > public static void printversion() { 10d9 < string rtn = null; 13d11 < class.forname("com.mysql.jdbc.driver").newinstance(); 19c17 < rtn = rs.getstring(1); --- > system.out.println(rs.getstring(1)); 43d40 < return rtn;
basically add class.forname("com.mysql.jdbc.driver").newinstance();
right before initialize connection.
i have absolutely 0 idea why would work without statement if i'm printing output wouldn't work if returning output. mega bonus-points whoever can describe me.
edit: borked diff
- need add exception handlers instantiationexception
, illegalaccessexception
, classnotfoundexception
well. ide should prompt of though.
Comments
Post a Comment