资源简介

采用Eclipse 编写的关于省市县三级菜单采用JSP +servlet+MYSQL ,数据库表的数据文件在src文件夹中 mysql> show tables; +----------------+ | Tables_in_area | +----------------+ | area | | cities | | provinces | +----------------+ 3 rows in set (0.00 sec) mysql> desc provinces; +----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | pid | char(6) | NO | | NULL | | | province | varchar(100) | NO | | | | +----------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) mysql> desc cities; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | cid | char(6) | NO | | NULL | | | city | varchar(40) | NO | | NULL | | | pid | char(6) | NO | | NULL | | +-------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec) mysql> desc area; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | aid | char(6) | NO | | NULL | | | area | varchar(40) | NO | | NULL | | | cid | char(6) | NO | | NULL | | +-------+-------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)

资源截图

代码片段和文件信息

package testajax.area;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DbConn {
Connection conn=null;
ResultSet  rs=null;
Statement  stmt=null;
private final String classdriver=“com.mysql.jdbc.Driver“;
private final String dbname=“area“;
private final String user=“root“;
private final String password=“zhang0817“;
private final String url=“jdbc:mysql://localhost:3306/“+dbname+“?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8&autoReconnect=true“;
public Connection getconn() {


try {
Class.forName(classdriver);
conn=DriverManager.getConnection(url user password);
//DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public ResultSet quarycity(String idString selectid String tablename) {
String sql=“select * from “+tablename+“ where “+selectid+“ = “+id+“ order by id“;
System.out.println(sql);
try {
rs=getconn().createStatement().executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet quaryProvincial() {
String sql=“select * from provinces“;
System.out.println(sql);
try {
rs=getconn().createStatement().executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public String quaryPCA(String sql){
StringBuffer sb=new StringBuffer();
try {
rs=getconn().createStatement().executeQuery(sql);
while(rs.next()) {
sb.append(rs.getString(“province“));
sb.append(rs.getString(“city“));
sb.append(rs.getString(“area“));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(sb.toString());
close();
return sb.toString();

}


public void close() {
try {
if (rs!=null) {
rs.close();;
}
if (conn!=null) {
conn.close();
}

} catch (Exception e) {
// TODO: handle exception
}
}
public static void main(String[] args) {
DbConn dbConn=new DbConn();
ResultSet rSet=dbConn.quaryProvincial();
try {
while (rSet.next()) {
try {
System.out.println(rSet.getInt(“pid“)+“:“+rSet.getString(“Provincial“));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-05-19 21:51  testajax\
     文件         951  2019-05-19 21:51  testajax\.classpath
     文件         908  2019-05-19 21:51  testajax\.project
     目录           0  2019-05-19 21:51  testajax\.settings\
     文件         567  2019-05-19 21:51  testajax\.settings\.jsdtscope
     文件         364  2019-05-19 21:51  testajax\.settings\org.eclipse.jdt.core.prefs
     文件         476  2019-05-19 21:51  testajax\.settings\org.eclipse.wst.common.component
     文件         305  2019-05-19 21:51  testajax\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2019-05-19 21:51  testajax\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2019-05-19 21:51  testajax\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2019-05-19 21:51  testajax\build\
     目录           0  2019-05-19 21:51  testajax\build\classes\
     目录           0  2019-05-19 21:51  testajax\build\classes\testajax\
     目录           0  2019-05-19 21:51  testajax\build\classes\testajax\area\
     文件      250586  2019-05-19 21:51  testajax\build\classes\testajax\area\area.sql
     文件        3868  2019-05-19 21:51  testajax\build\classes\testajax\area\DbConn.class
     文件        2580  2019-05-19 21:51  testajax\build\classes\testajax\area\GetArea.class
     文件        2596  2019-05-19 21:51  testajax\build\classes\testajax\area\GetCity.class
     目录           0  2019-05-19 21:51  testajax\src\
     目录           0  2019-05-19 21:51  testajax\src\testajax\
     目录           0  2019-05-19 21:51  testajax\src\testajax\area\
     文件      250586  2019-05-19 21:51  testajax\src\testajax\area\area.sql
     文件        2894  2019-05-19 21:51  testajax\src\testajax\area\DbConn.java
     文件        1728  2019-05-19 21:51  testajax\src\testajax\area\GetArea.java
     文件        1856  2019-05-19 21:51  testajax\src\testajax\area\GetCity.java
     目录           0  2019-05-19 21:51  testajax\WebContent\
     目录           0  2019-05-19 21:51  testajax\WebContent\area\
     文件        3186  2019-05-19 21:51  testajax\WebContent\area\area.jsp
     文件         724  2019-05-19 21:51  testajax\WebContent\area\getarea.jsp
     文件         999  2019-05-19 21:51  testajax\WebContent\area\readme
     文件         198  2019-05-19 21:51  testajax\WebContent\index.html
............此处省略5个文件信息

评论

共有 条评论