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

一、數(shù)據(jù)庫的設(shè)計
我們需要了解數(shù)據(jù)庫的設(shè)計。數(shù)據(jù)庫的設(shè)計包括三層結(jié)構(gòu),分別為外模型、邏輯模型和物理模型。外模型是針對用戶的,也就是用戶能夠看到和使用的模型;邏輯模型是對于數(shù)據(jù)庫內(nèi)部結(jié)構(gòu)的抽象,是一種中間層;物理模型則是和具體的數(shù)據(jù)庫管理軟件有關(guān)系的,是一種具體實現(xiàn)。
在設(shè)計數(shù)據(jù)庫時,我們需要考慮以下幾點:
1. 數(shù)據(jù)庫設(shè)計應(yīng)該符合范式。
2. 字段名應(yīng)該與業(yè)務(wù)相關(guān),語義明確。
3. 數(shù)據(jù)類型應(yīng)該選擇符合實際情況的類型,避免數(shù)據(jù)冗余。
4. 數(shù)據(jù)庫命名應(yīng)該以業(yè)務(wù)為主,簡潔明了。
二、SQL查詢語句
在數(shù)據(jù)庫的使用過程中,SQL查詢語句是必不可少的。SQL是結(jié)構(gòu)化查詢語言的縮寫,是操作數(shù)據(jù)庫的通用語言。下面介紹一些常用的SQL查詢語句:
1. SELECT:查詢數(shù)據(jù),常用語句。
2. WHERE:用于篩選符合條件的數(shù)據(jù)。
3. GROUP BY:按照某個字段進行分組。
4. ORDER BY:按照某個字段進行排序。
5. JOIN:將多個表連接起來進行查詢。
6. HAVING:用于篩選分組后符合條件的數(shù)據(jù)。
三、省市區(qū)信息的查詢
在查詢省市區(qū)信息時,我們需要涉及到中國地圖的經(jīng)緯度信息,同時需要有城市與行政區(qū)劃的對照表。下面以查詢北京市信息為例,介紹如何查詢省市區(qū)信息。
1. 查詢北京市行政區(qū)劃信息
北京市行政區(qū)劃信息包括了市、區(qū)、街道辦事處等信息,我們需要查詢的是這些信息,并將其按照層級顯示。查詢語句如下:
SELECT * FROM area WHERE area_name = ‘北京市’;
其中,area_name表示地區(qū)名稱,* 表示全部字段。
2. 查詢北京市各區(qū)縣信息
查詢北京市各區(qū)縣信息時,我們需要使用到“JOIN”語句,將中國城市及行政區(qū)劃對照表與其它信息表連接起來進行查詢。查詢語句如下:
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ù)實際需求進行查詢,同時結(jié)合SQL語法進行提高效率。希望本文對您有所幫助。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián),建站經(jīng)驗豐富以策略為先導(dǎo)10多年以來專注數(shù)字化網(wǎng)站建設(shè),提供企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,響應(yīng)式網(wǎng)站制作,設(shè)計師量身打造品牌風(fēng)格,熱線:028-86922220誰有全國銀行的聯(lián)行號數(shù)據(jù)庫,更好是省市區(qū)版的
有個網(wǎng)站可以,你百度試試,我就是在百度上找的,仔細點就能找到。
省市區(qū) 地址聯(lián)動 數(shù)據(jù)怎么創(chuàng)建
1、在做這個小項目前的準(zhǔn)備工作:
1.1、分析:
由于省、市、縣城(區(qū))這些數(shù)據(jù)是存儲到了MySQL數(shù)據(jù)庫中的,我們要通過后臺servlet獲取數(shù)據(jù)庫中的數(shù)據(jù),然后再通過轉(zhuǎn)發(fā)或者重定向的方式將數(shù)據(jù)呈現(xiàn)到前臺頁面中。
1.2、需要導(dǎo)入的jar包有:
mysql驅(qū)動包:mysql-connector-Java-5.1.7-bin.jar
c3p0數(shù)據(jù)庫連接池:c3p0-0.9.2.1.jar、mysql-connector-java-5.1.7-bin.jar(c3p0依賴包)
前臺c標(biāo)簽(需要通過遍歷的方式呈現(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
前臺頁面需要用到j(luò)Query,故還需要導(dǎo)入jquery-1.7.2.js庫文件
1.3、該小項目用到的技術(shù):
jdbc的知識、servlet的知識、jquery的知識、Ajax的知識(局部刷新)、標(biāo)簽的知識、EL表達式的知識、P的知識
2、開發(fā)過程:
2.1、準(zhǔn)備數(shù)據(jù)源
創(chuàng)建一個數(shù)據(jù)庫,命名為thereaction并創(chuàng)建三個表——province(省)、city(市)、county(縣/區(qū))
2.2后臺開發(fā)
創(chuàng)建三個Javabean分別是Province、City、County。(由于太過簡單,這里就不粘代碼了)
創(chuàng)建Java類和c3p0連接池實現(xiàn)與數(shù)據(jù)庫的連接:DAO.java(實現(xiàn)獲取數(shù)據(jù)庫數(shù)據(jù)的功能)、jdbctools.java(實現(xiàn)獲取數(shù)據(jù)庫連接、釋放連接的功能)、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ù)庫連接池應(yīng)只被初始化一次
static{
ds=new ComboPooledDataSource(“helloc3p0”);
}
//獲取數(shù)據(jù)庫連接
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ù)庫
Connection ct=null;
ct=Jdbctools.getConnection();
System.out.println(“獲取到數(shù)據(jù)庫的連接了”);
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ù)庫
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ù)庫
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進入了”);
String sql=”select province_id,province_name from province”;
List provinces=dao.getprovince(sql);
request.setAttribute(“provinces”, provinces);
System.out.println(provinces);
//注意:這里不能用重定向的形式,因為我們好不容易在request請求域中存儲了省的信息,目的是在前臺頁面中能夠從請求域中獲取到我們存在數(shù)據(jù)庫中的值
//故這里只能用轉(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進入了”);
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進入了”);
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);
}
我們在程序中經(jīng)常用到 全國省市縣三級聯(lián)動 選擇地址,那樣的話 保存到數(shù)據(jù)庫中是一個字段還是三個字段
說白了 就是一友源個樹 每個地區(qū)名都有一個 父地區(qū)節(jié)點
1 中國 0
2 河北 1
3 河南 1
4 滄州 2
不過我不建議這么做 這些數(shù)據(jù)都是死的 你可以寫在一個js里 然后衡兄用數(shù)組的形式調(diào)出來 減少數(shù)據(jù)庫好攔態(tài)查詢
三個字段的,省、市、縣
看你要不要做統(tǒng)計匯總陪薯之類的..
如果只是填個資料,1個字段就行了,省市縣用#,$,&這些特殊符號隔開..
如果后期要做歸納,搜索這樣的功能謹唯,那還是祥亂培分3個字段
省市區(qū)數(shù)據(jù)庫查詢的介紹就聊到這里吧,感謝你花時間閱讀本站內(nèi)容,更多關(guān)于省市區(qū)數(shù)據(jù)庫查詢,查詢省市區(qū)信息的數(shù)據(jù)庫技巧,誰有全國銀行的聯(lián)行號數(shù)據(jù)庫,更好是省市區(qū)版的,省市區(qū) 地址聯(lián)動 數(shù)據(jù)怎么創(chuàng)建,我們在程序中經(jīng)常用到 全國省市縣三級聯(lián)動 選擇地址,那樣的話 保存到數(shù)據(jù)庫中是一個字段還是三個字段的信息別忘了在本站進行查找喔。
創(chuàng)新互聯(lián)【028-86922220】值得信賴的成都網(wǎng)站建設(shè)公司。多年持續(xù)為眾多企業(yè)提供成都網(wǎng)站建設(shè),成都品牌建站設(shè)計,成都高端網(wǎng)站制作開發(fā),SEO優(yōu)化排名推廣服務(wù),全網(wǎng)營銷讓企業(yè)網(wǎng)站產(chǎn)生價值。
新聞標(biāo)題:查詢省市區(qū)信息的數(shù)據(jù)庫技巧(省市區(qū)數(shù)據(jù)庫查詢)
標(biāo)題路徑:http://www.5511xx.com/article/djigpep.html


咨詢
建站咨詢
