jdbc error java class trying to connect to linux mysql server -
my error!
dbconnection2.java:38: unreported exception java.lang.instantiationexception; must caught or declared thrown class.forname("com.mysql.jdbc.driver").newinstance();
problem: .newinstance();
my code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; import java.util.*; import java.sql.*; import java.util.stringtokenizer; public class dbconnection2 { string url = "jdbc:mysql://<myserver>/<mydatabase>"; java.sql.connection con = null; string query1; statement stmt; public dbconnection2() { try { //***error here***** class.forname("com.mysql.jdbc.driver").newinstance(); //***error here***** } catch(java.lang.classnotfoundexception e) { system.err.println(e.getmessage()); } try { con = java.sql.drivermanager.getconnection(url,"read","read"); stmt = con.createstatement(); } catch(sqlexception ex) { system.err.println("sqlexception:72 appserver " + ex.getmessage()); } } }
the error says is. new instance instantiation through reflection needs handled (caught or thrown).
that said, aren't doing new instance - aren't assigning , in case, doesn't need called.
class.forname("com.mysql.jdbc.driver");
just - fix error.
realize still has other problems lurking in code - 1 of if have error of not being able load class, print out error message, continue on in next try block , error out again there.
Comments
Post a Comment