Product Catalog/implementation of Forum tree structure-JSP tutorial, object-oriented/Design

Source: Internet
Author: User
Tags odbc stmt
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 name =" FatherID "class =" p9 ">" +
"<Option value ="-1 "selected> select the parent class </option> ";
String SQL = null;
SQL = "select * from catalog order by AncestorID, Linkstr ";
ResultSet rs1_conn.exe cute (SQL );
Try {
While (rs. next ()){
Str = str + "<option value =" + rs. getString ("Productid") + "> ";
Int nbspCount = rs. getString ("LinkStr"). length ()-1;
For (int I = 0; I <nbspCount; I ++ ){
Str = str + "";
}
If (nbspCount> 0)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.