java - Connection and SqlServerConnection mismatch -
apologies terminilogy used.
i have generic class want utilize fill jxcomboboxes. looks this:
package fillers; import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import org.jdesktop.swingx.jxcombobox; public class comboboxfiller { private connection connconnection; private jxcombobox cbocombobox; private string strcomboboxquery; public comboboxfiller(connection connutooldb, jxcombobox cbocombobox, string strcomboboxquery) throws sqlexception { this.connconnection = connutooldb; this.cbocombobox = cbocombobox; this.strcomboboxquery = strcomboboxquery; fill(); } public void fill() throws sqlexception { resultset rscombobox = null; preparedstatement prepstmntcombobbox = null; seek { prepstmntcombobbox = connconnection.preparestatement(strcomboboxquery,resultset.type_scroll_insensitive, resultset.concur_read_only); rscombobox = prepstmntcombobbox.executequery(); cbocombobox.removeallitems(); while (rscombobox.next()) { string comboboxitem = rscombobox.getstring(1); cbocombobox.additem(comboboxitem); } } { seek { rscombobox.close(); prepstmntcombobbox.close(); } grab (exception e) { e.printstacktrace(); } } } } the database utilize sqlserver database. connect database utilize generic class. looks this.
package dbconnections; import java.sql.connection; import java.sql.drivermanager; import java.sql.sqlexception; public class jdbcsqlserverconnection { private connection connjdbcsqlserver; public void connect(string dburl) throws classnotfoundexception { seek { //drivermanager.registerdriver(new sqlserverdriver()); class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); setconnjdbcsqlserver(drivermanager.getconnection(dburl)); system.out.println("connected sqlserver"); } grab (sqlexception ex) { ex.printstacktrace(); } } public connection getconnjdbcsqlserver() { homecoming connjdbcsqlserver; } public void setconnjdbcsqlserver(connection connjdbcsqlserver) { this.connjdbcsqlserver = connjdbcsqlserver; } public void close(){ seek { connjdbcsqlserver.close(); system.out.println("sqlserver connection closed..."); } grab (sqlexception e) { // todo auto-generated grab block e.printstacktrace(); } } } the problem comes in when want fill combobox using sqlserverconnection (com.microsoft.sqlserver.jdbc.sqlserverdriver) because jxcomboboxfiller expects "normal" connection (java.sql.connection).
how bridge this? cant wrap head around this.
get connection jdbcsqlserverconnection calling getconnjdbcsqlserver , pass returned object comboboxfilter
for example:
jdbcsqlserverconnection sqlconnection= new jdbcsqlserverconnection(path); sqlconnection.connect(); connection connection = sqlconnection.getconnjdbcsqlserver(); comboboxfiller(connection,...); java eclipse connections
No comments:
Post a Comment