Importjava. SQL. *; publicclassCoalTotals {*** @ paramargs * publicstaticvoidmain (String [] args) {TODOAuto-generatedmethodstubtry {load the driver Class supported by the database. forName (sun. jdbc. odbc. jdbcOdbcDriver); Stringurljdbc: odbc: Drive
Import java. SQL. *; public class CoalTotals {/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stubtry {// load the driver Class supported by the database. forName ("sun. jdbc. odbc. jdbcOdbcDriver "); String url =" jdbc: odbc: Drive
Import java. SQL. *; public class CoalTotals {/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stubtry {// load the driver Class supported by the database. forName ("sun. jdbc. odbc. jdbcOdbcDriver "); String url =" jdbc: odbc: Driver = {Microsoft Access Driver (*. mdb)}; DBQ = E: // Dev // WorkSpace // chapter21 // bin // worlddeskmdb "; try {// establish a data source Connection conn = DriverManager. getConnection (url, "", ""); Statement st = conn. createStatement (); ResultSet rec = st.exe cuteQuery ("select *" + "from Coal"); System. out. println ("FIPS/tCOUNTRY/tYEAR/t" + "anthracite production"); while (rec. next () {System. out. println (rec. getString (1) + "/t" + rec. getString (2) + "/t" + rec. getString (3) + "/t" + rec. getString (4);} st. close ();} catch (SQLException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke. printStackTrace ();}}}
The url Connection here must be careful not to use multiple spaces with only one space. Because when I write an extra space, the system will prompt that the file name is incorrect.
Other steps to connect to the database are basically no big problem ~~