For jsp servers set up in windows, and the system is relatively small, using access is a good choice, but to use an access database usually through the data source. Here we provide a method to directly connect to the data source without using the data source using java. The example program is as follows: importjava. SQL. *; publicclassAccess {publicstaticvoidmain (Strin AccessJDBCODBC
For jsp servers set up in windows, and the system is relatively small, using access is a good choice, but to use an access database usually through the data source. Here we provide a method to directly connect to the data source without using the data source using java. The example program is as follows:
Importjava. SQL .*;
PublicclassAccess
{
Publicstaticvoidmain (Stringargs [])
{
Try
{
Stringstrurl = "jdbc: odbc: driver = {MicrosoftAccessDriver (*. mdb)}; DBQ = books. mdb ";
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
Connectionconn = DriverManager. getConnection (strurl );
Statementstmt = conn. createStatement ();
Resultsetrs1_stmt.exe cuteQuery ("select * frombooks ");
If (rs. next ())
{
System. out. println (rs. getString ("Introduction "));
}
} Catch (effectione)
{
System. out. println (e );
}
}
}
You can see that you do not need to set the data source as long as you add an odbc driver to the driver. this method should also apply to other small databases (such as forpro.
(Source: CSDN)