Package ODBC; <br/> Import Java. SQL. *; <br/> public class testora {</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) {<br/> // todo auto-generated method stub </P> <p> try {<br/> // step1.add drives <br/> class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver "); <br/> // step2.get connection <br/> connection conn = drivermanager. getconnection ("JDBC: ODBC: dhyora", "Scott", "Tiger"); <br/> // step3.creat statement <br/> statement Sm = Conn. createstatement (); <br/> // step4.result set <br/> resultset rs1_sm.exe cutequery ("select * from EMP"); <br/> while (RS. next () {// has next <br/> system. out. println ("username:" + Rs. getstring (2); <br/>}< br/> // step5.close all <br/> Rs. close (); <br/> SM. close (); <br/> Conn. close (); <br/>}< br/> catch (exception e) {<br/> E. printstacktrace (); <br/>}</P> <p>}
Note: to add a data source in the data source (ODBC): dhyora