In this example, access is used as an instance, and there are still many improvements. Please improve packagePRodUCt; importjava. SQL. *; publicclassConnectDB {StringstrDBDriversun. jdbc. odbc. JdbcOdbcDriver; StringstrConnstrjdbc: odbc: product; Connectionconnnull; ResultSetrs
In this example, access is used as an instance, and there are still many improvements. Please improve packagePRodUCt; importjava. SQL. *; publicclassConnectDB {StringstrDBDriver = sun. jdbc. odbc. JdbcOdbcDriver; StringstrConnstr = jdbc: odbc: product; Connectionconn = null; ResultSetrs =
In this example, access is used as an instance, and there are still many improvements.
Please improve yourself
Package PRodUCt;
Import java. SQL .*;
Public class ConnectDB {
String strDBDriver = "sun. jdbc. odbc. JdbcOdbcDriver ";
String strConnstr = "jdbc: odbc: product ";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
// Statement stmt = null;
// Constructor
Public ConnectDB (){
Try {
Class. forName (strDBDriver); conn = DriverManager. getConnection (strConnstr );
Stmt = conn. createStatement ();
}
Catch (Exception e ){
System. out. println (e );
}
}
Public ResultSet execute (String SQL ){
Rs = null;
Try {
Rs1_stmt.exe cuteQuery (SQL );
}
Catch (SQLException e ){
System. out. println (e. getMessage ());
}
Return rs;
}
Public Connection getConnection (){
Return conn;
}
Public boolean close (){
Try {
If (this. rs! = Null ){
This. rs. close ();
}
If (stmt! = Null ){
This. stmt. close ();
}
If (conn! = Null ){
This. conn. close ();
}
Return true;
} Catch (Exception err ){
Return false;
}
}
}
// ================================================ =
Package product;
Import java. SQL .*;
Public class catalog
{
ConnectDB conn = new ConnectDB ();
String str = null;
String SQL = null;
ResultSet rs = null;
String AncestorID, LinkStr;
Public String getCatalog (){
Str =" "+"Select parent class";String SQL = null;SQL = "select * from catalog order by AncestorID, Linkstr ";ResultSet rs1_conn.exe cute (SQL );Try {While (rs. next ()){Str = str +"";Int nbspCount = rs. getString ("LinkStr"). length ()-1;