1. JDBC operations on the Access Database
Http://www.blogjava.net/pixysoft/archive/2007/09/09/143731.html
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver");
String Database= "JDBC: ODBC: Driver = {Microsoft Access Driver (*. mdb)}; DBQ = demo. MDB";
Connection con=Drivermanager. getconnection (database,"","");
Statement S=Con. createstatement ();
S.exe cute ("Select ID, name, memo from demo where id =" +ID );
Resultset rs=S. getresultset ();
If(RS! = Null)
{
While(Rs. Next ())
{
Byte[] Image=Rs. getbytes (3);
Memo= NewString (image,"Gb2312");
}
}
S. Close ();
Con. Close ();
2. Getting started with JDBC:
Http://java.sun.com/docs/books/tutorial/jdbc/overview/index.html
Http://java.sun.com/docs/books/tutorial/jdbc/basics/transactions.html
Use transactions.
When a connection is created, it is in auto-commit mode.
Con. setautocommit (false );
Con. setautocommit (false); preparedstatement updatesales = con. preparestatement ("Update coffees set sales =? Where cof_name like? "); Updatesales. setint (1, 50); updatesales. setstring (2, "Colombian" );updatesales.exe cuteupdate (); preparedstatement updatetotal = con. preparestatement ("Update coffees set total = total +? Where cof_name like? "); Updatetotal. setint (1, 50); updatetotal. setstring (2," Colombian ");updatetotal.exe cuteupdate (); con. Commit ();
Con. setautocommit (true );
Http://www.360doc.com/content/06/1118/14/14474_264128.shtml
Http://java.chinaitlab.com/JDBCJDO/734413.html
Implementation of a simple JDBC connection pool (1)
Each request for a connection establishes a communication connection on the physical network (such as the TCP/IP network). A certain number of statement can be applied for this connection.
Http://java.chinaitlab.com/JDBCJDO/734416.html
Implementation of a simple JDBC connection pool (2)
Http://www.cnblogs.com/pony/archive/2008/11/17/1335227.html
Get table structure in Java
Databasemetadata dbmd = con. getmetadata ();
Rs = dbmd. getcolumns (con. getcatalog (), schema, tablename, null );
Rs. getstring (data_type) Java. SQL. types SQL type
The size of the RS. getstring (column_size) column. For the char or date type, the column size is the maximum number of characters. For the numeric and decimal types, the column size is the precision.
The number of digits in the decimal part of Rs. getstring (decimal_digits ).
2. The following describes how to obtain table information.
M_dbmetadata = m_connection.getmetadata ();
Resultset tableret = m_dbmetadata.gettables (null, "%", m_tablename, new string [] {"table "});
3. Extract the table name.
While (tableret. Next) system. Out. println (tableret. getstring ("table_name "));
You can use getstring ("table_name") to obtain the table name.
It can be seen from this that JDBC stores all the results returned through the gettables interface in a memory structure similar to a table, the table_name field is the name of each table.
4. Extract the names and types of fields in the table.
String columnname;
String columntype;
Resultset colret = m_dbmetadata.getcolumns (null, "%", m_tablename, "% ");
While (colret. Next ()){
Columnname = colret. getstring ("column_name ");
Columntype = colret. getstring ("type_name ");
Int datasize = colret. getint ("column_size ");
Int digits = colret. getint ("decimal_digits ");
Int nullable = colret. getint ("nullable ");
System. Out. println (columnname + "" + columntype + "" + datasize + "" + digits + "" +
Nullable );
}
In JDBC, The getcolumns interface is used to query fields. Like gettables, "%" indicates all arbitrary fields, while m_tablename indicates the name of the data table.
Http://blog.csdn.net/alihoo/archive/2008/06/23/2578252.aspx
Resultset pkrset = dbmeta. getprimarykeys (Null,Null, "Comment ");
While(Pkrset. Next ()){
System. Err. println ("******* comment ******");
System. Err. println ("table_cat:" + pkrset. GetObject (1 ));
System. Err. println ("table_schem:" + pkrset. GetObject (2 ));
System. Err. println ("table_name:" + pkrset. GetObject (3 ));
System. Err. println ("column_name:" + pkrset. GetObject (4 ));
System. Err. println ("key_seq:" + pkrset. GetObject (5 ));
System. Err. println ("pk_name:" + pkrset. GetObject (6 ));
System. Err. println ("*******************");
}