新聞中心
隨著互聯(lián)網(wǎng)的發(fā)展,省市區(qū)信息查詢已經(jīng)成為了日常生活中不可或缺的事情。同時(shí),隨著對(duì)于城市規(guī)劃的越來(lái)越重視,對(duì)于省市區(qū)信息的需求也越來(lái)越高。在這種情況下,我們需要能夠高效地。

一、數(shù)據(jù)庫(kù)的設(shè)計(jì)
我們需要了解數(shù)據(jù)庫(kù)的設(shè)計(jì)。數(shù)據(jù)庫(kù)的設(shè)計(jì)包括三層結(jié)構(gòu),分別為外模型、邏輯模型和物理模型。外模型是針對(duì)用戶的,也就是用戶能夠看到和使用的模型;邏輯模型是對(duì)于數(shù)據(jù)庫(kù)內(nèi)部結(jié)構(gòu)的抽象,是一種中間層;物理模型則是和具體的數(shù)據(jù)庫(kù)管理軟件有關(guān)系的,是一種具體實(shí)現(xiàn)。
在設(shè)計(jì)數(shù)據(jù)庫(kù)時(shí),我們需要考慮以下幾點(diǎn):
1. 數(shù)據(jù)庫(kù)設(shè)計(jì)應(yīng)該符合范式。
2. 字段名應(yīng)該與業(yè)務(wù)相關(guān),語(yǔ)義明確。
3. 數(shù)據(jù)類型應(yīng)該選擇符合實(shí)際情況的類型,避免數(shù)據(jù)冗余。
4. 數(shù)據(jù)庫(kù)命名應(yīng)該以業(yè)務(wù)為主,簡(jiǎn)潔明了。
二、SQL查詢語(yǔ)句
在數(shù)據(jù)庫(kù)的使用過(guò)程中,SQL查詢語(yǔ)句是必不可少的。SQL是結(jié)構(gòu)化查詢語(yǔ)言的縮寫,是操作數(shù)據(jù)庫(kù)的通用語(yǔ)言。下面介紹一些常用的SQL查詢語(yǔ)句:
1. SELECT:查詢數(shù)據(jù),常用語(yǔ)句。
2. WHERE:用于篩選符合條件的數(shù)據(jù)。
3. GROUP BY:按照某個(gè)字段進(jìn)行分組。
4. ORDER BY:按照某個(gè)字段進(jìn)行排序。
5. JOIN:將多個(gè)表連接起來(lái)進(jìn)行查詢。
6. HAVING:用于篩選分組后符合條件的數(shù)據(jù)。
三、省市區(qū)信息的查詢
在查詢省市區(qū)信息時(shí),我們需要涉及到中國(guó)地圖的經(jīng)緯度信息,同時(shí)需要有城市與行政區(qū)劃的對(duì)照表。下面以查詢北京市信息為例,介紹如何查詢省市區(qū)信息。
1. 查詢北京市行政區(qū)劃信息
北京市行政區(qū)劃信息包括了市、區(qū)、街道辦事處等信息,我們需要查詢的是這些信息,并將其按照層級(jí)顯示。查詢語(yǔ)句如下:
SELECT * FROM area WHERE area_name = ‘北京市’;
其中,area_name表示地區(qū)名稱,* 表示全部字段。
2. 查詢北京市各區(qū)縣信息
查詢北京市各區(qū)縣信息時(shí),我們需要使用到“JOIN”語(yǔ)句,將中國(guó)城市及行政區(qū)劃對(duì)照表與其它信息表連接起來(lái)進(jìn)行查詢。查詢語(yǔ)句如下:
SELECT a.area_name AS province_name, b.area_name AS city_name, c.area_name AS area_name FROM area a
LEFT JOIN area b ON a.id = b.parent_id
LEFT JOIN area c ON b.id = c.parent_id WHERE a.area_name = ‘北京市’ and c.level = 3;
其中,a.area_name表示省名,b.area_name表示市名,c.area_name表示區(qū)名,level表示區(qū)劃層級(jí)。
以上就是,我們需要根據(jù)實(shí)際需求進(jìn)行查詢,同時(shí)結(jié)合SQL語(yǔ)法進(jìn)行提高效率。希望本文對(duì)您有所幫助。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián),建站經(jīng)驗(yàn)豐富以策略為先導(dǎo)10多年以來(lái)專注數(shù)字化網(wǎng)站建設(shè),提供企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),響應(yīng)式網(wǎng)站制作,設(shè)計(jì)師量身打造品牌風(fēng)格,熱線:028-86922220誰(shuí)有全國(guó)銀行的聯(lián)行號(hào)數(shù)據(jù)庫(kù),更好是省市區(qū)版的
有個(gè)網(wǎng)站可以,你百度試試,我就是在百度上找的,仔細(xì)點(diǎn)就能找到。
省市區(qū) 地址聯(lián)動(dòng) 數(shù)據(jù)怎么創(chuàng)建
1、在做這個(gè)小項(xiàng)目前的準(zhǔn)備工作:
1.1、分析:
由于省、市、縣城(區(qū))這些數(shù)據(jù)是存儲(chǔ)到了MySQL數(shù)據(jù)庫(kù)中的,我們要通過(guò)后臺(tái)servlet獲取數(shù)據(jù)庫(kù)中的數(shù)據(jù),然后再通過(guò)轉(zhuǎn)發(fā)或者重定向的方式將數(shù)據(jù)呈現(xiàn)到前臺(tái)頁(yè)面中。
1.2、需要導(dǎo)入的jar包有:
mysql驅(qū)動(dòng)包:mysql-connector-Java-5.1.7-bin.jar
c3p0數(shù)據(jù)庫(kù)連接池:c3p0-0.9.2.1.jar、mysql-connector-java-5.1.7-bin.jar(c3p0依賴包)
前臺(tái)c標(biāo)簽(需要通過(guò)遍歷的方式呈現(xiàn)——c:forEach):jstl-1.0.2.jar、standard-1.0.1.jar(jstl依賴包)
將或者數(shù)組轉(zhuǎn)換成json數(shù)據(jù)格式(Jackson包):jackson-annotations-2.2.1.jar、jackson-core-2.2.1.jar、jackson-databind-2.2.1.jar
前臺(tái)頁(yè)面需要用到j(luò)Query,故還需要導(dǎo)入jquery-1.7.2.js庫(kù)文件
1.3、該小項(xiàng)目用到的技術(shù):
jdbc的知識(shí)、servlet的知識(shí)、jquery的知識(shí)、Ajax的知識(shí)(局部刷新)、標(biāo)簽的知識(shí)、EL表達(dá)式的知識(shí)、P的知識(shí)
2、開發(fā)過(guò)程:
2.1、準(zhǔn)備數(shù)據(jù)源
創(chuàng)建一個(gè)數(shù)據(jù)庫(kù),命名為thereaction并創(chuàng)建三個(gè)表——province(?。?、city(市)、county(縣/區(qū))
2.2后臺(tái)開發(fā)
創(chuàng)建三個(gè)Javabean分別是Province、City、County。(由于太過(guò)簡(jiǎn)單,這里就不粘代碼了)
創(chuàng)建Java類和c3p0連接池實(shí)現(xiàn)與數(shù)據(jù)庫(kù)的連接:DAO.java(實(shí)現(xiàn)獲取數(shù)據(jù)庫(kù)數(shù)據(jù)的功能)、jdbctools.java(實(shí)現(xiàn)獲取數(shù)據(jù)庫(kù)連接、釋放連接的功能)、c3p0-config.xml
jdbctools.java代碼如下:
view plain copy
package com.xiaojie.dao;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class Jdbctools {
private static DataSource ds=null;
//數(shù)據(jù)庫(kù)連接池應(yīng)只被初始化一次
static{
ds=new ComboPooledDataSource(“helloc3p0”);
}
//獲取數(shù)據(jù)庫(kù)連接
public static Connection getConnection() throws ClassNotFoundException, SQLException, IOException{
return ds.getConnection();
}
public static void shifanglianjie(Connection ct, PreparedStatement ps,ResultSet rs) {
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(ps!=null){
try {
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(ct!=null){
try {
ct.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
DAO.java的代碼如下
view plain copy
package com.xiaojie.dao;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.xiaojie.beans.City;
import com.xiaojie.beans.County;
import com.xiaojie.beans.Province;
public class DAO {
public List getprovince(String sql ,Object…args) throws ClassNotFoundException, SQLException, IOException{
List provinces=new ArrayList();
//準(zhǔn)備去查數(shù)據(jù)庫(kù)
Connection ct=null;
ct=Jdbctools.getConnection();
System.out.println(“獲取到數(shù)據(jù)庫(kù)的連接了”);
PreparedStatement ps=null;
ResultSet rs=null;
ps=ct.prepareStatement(sql);
for(int i=0;i getcity(String sql ,Object…args) throws SQLException, ClassNotFoundException, IOException{
List cities=new ArrayList();
//準(zhǔn)備去查數(shù)據(jù)庫(kù)
Jdbctools jt=new Jdbctools();
Connection ct=null;
ct=jt.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
ps=ct.prepareStatement(sql);
for(int i=0;i getcounty(String sql,Object…args ) throws SQLException, ClassNotFoundException, IOException{
List counties=new ArrayList();
//準(zhǔn)備去查數(shù)據(jù)庫(kù)
Jdbctools jt=new Jdbctools();
Connection ct=null;
ct=jt.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
ps=ct.prepareStatement(sql);
for(int i=0;i
root
com.mysql.jdbc.Driver
jdbc:
創(chuàng)建servlet.java 文件
view plain copy
package com.xiaojie.servlet;
import java.io.IOException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaojie.beans.City;
import com.xiaojie.beans.County;
import com.xiaojie.beans.Province;
import com.xiaojie.dao.DAO;
/**
* Servlet implementation class ThreeactiondServlet
*/
@WebServlet(“/threeactiondServlet”)
public class ThreeactiondServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String methodname=request.getParameter(“method”);
try {
Method method=getClass().getDeclaredMethod(methodname,HttpServletRequest.class,HttpServletResponse.class);
method.invoke(this, request,response);//調(diào)用各自的方法
} catch (Exception e) {
e.printStackTrace();
}
}
private DAO dao=new DAO();
protected void province(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
System.out.println(“province的servlet進(jìn)入了”);
String sql=”select province_id,province_name from province”;
List provinces=dao.getprovince(sql);
request.setAttribute(“provinces”, provinces);
System.out.println(provinces);
//注意:這里不能用重定向的形式,因?yàn)槲覀兒貌蝗菀自趓equest請(qǐng)求域中存儲(chǔ)了省的信息,目的是在前臺(tái)頁(yè)面中能夠從請(qǐng)求域中獲取到我們存在數(shù)據(jù)庫(kù)中的值
//故這里只能用轉(zhuǎn)發(fā)的方式
request.getRequestDispatcher(“/index2.jsp”).forward(request, response);
}
protected void city(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
System.out.println(“city的servlet進(jìn)入了”);
String province_id=request.getParameter(“province_id”);
String sql=”select city_id,city_name from city where province_id=?”;
List cities=dao.getcity(sql,Integer.parseInt(province_id));
ObjectMapper mapper=new ObjectMapper();
String result=mapper.writeValueAsString(cities);
System.out.println(result);
response.setContentType(“text/javascript”);
response.getWriter().print(result);
}
protected void county(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException {
System.out.println(“county的servlet進(jìn)入了”);
String city_id=request.getParameter(“city_id”);
String sql=”select county_id,county_name from county where city_id=?”;
List counties=dao.getcounty(sql,Integer.parseInt(city_id));
ObjectMapper mapper=new ObjectMapper();
String result=mapper.writeValueAsString(counties);
System.out.println(result);
response.setContentType(“text/javascript”);
response.getWriter().print(result);
}
我們?cè)诔绦蛑薪?jīng)常用到 全國(guó)省市縣三級(jí)聯(lián)動(dòng) 選擇地址,那樣的話 保存到數(shù)據(jù)庫(kù)中是一個(gè)字段還是三個(gè)字段
說(shuō)白了 就是一友源個(gè)樹 每個(gè)地區(qū)名都有一個(gè) 父地區(qū)節(jié)點(diǎn)
1 中國(guó) 0
2 河北 1
3 河南 1
4 滄州 2
不過(guò)我不建議這么做 這些數(shù)據(jù)都是死的 你可以寫在一個(gè)js里 然后衡兄用數(shù)組的形式調(diào)出來(lái) 減少數(shù)據(jù)庫(kù)好攔態(tài)查詢
三個(gè)字段的,省、市、縣
看你要不要做統(tǒng)計(jì)匯總陪薯之類的..
如果只是填個(gè)資料,1個(gè)字段就行了,省市縣用#,$,&這些特殊符號(hào)隔開..
如果后期要做歸納,搜索這樣的功能謹(jǐn)唯,那還是祥亂培分3個(gè)字段
省市區(qū)數(shù)據(jù)庫(kù)查詢的介紹就聊到這里吧,感謝你花時(shí)間閱讀本站內(nèi)容,更多關(guān)于省市區(qū)數(shù)據(jù)庫(kù)查詢,查詢省市區(qū)信息的數(shù)據(jù)庫(kù)技巧,誰(shuí)有全國(guó)銀行的聯(lián)行號(hào)數(shù)據(jù)庫(kù),更好是省市區(qū)版的,省市區(qū) 地址聯(lián)動(dòng) 數(shù)據(jù)怎么創(chuàng)建,我們?cè)诔绦蛑薪?jīng)常用到 全國(guó)省市縣三級(jí)聯(lián)動(dòng) 選擇地址,那樣的話 保存到數(shù)據(jù)庫(kù)中是一個(gè)字段還是三個(gè)字段的信息別忘了在本站進(jìn)行查找喔。
創(chuàng)新互聯(lián)【028-86922220】值得信賴的成都網(wǎng)站建設(shè)公司。多年持續(xù)為眾多企業(yè)提供成都網(wǎng)站建設(shè),成都品牌建站設(shè)計(jì),成都高端網(wǎng)站制作開發(fā),SEO優(yōu)化排名推廣服務(wù),全網(wǎng)營(yíng)銷讓企業(yè)網(wǎng)站產(chǎn)生價(jià)值。
網(wǎng)站欄目:查詢省市區(qū)信息的數(shù)據(jù)庫(kù)技巧(省市區(qū)數(shù)據(jù)庫(kù)查詢)
文章起源:http://www.fisionsoft.com.cn/article/djigpep.html


咨詢
建站咨詢
