Home Database Mysql Tutorial Spring MVC 链接 PostgreSQL

Spring MVC 链接 PostgreSQL

Jun 07, 2016 pm 04:08 PM
spring mvc

前面一篇文章已经分享了搭建Spring MVC:http://www.linuxidc.com/Linux/2015-02/113103.htm 这一篇来链接数据库PostgreSQL 1、在

前面一篇文章已经分享了搭建Spring MVC:

这一篇来链接数据库PostgreSQL

1、在pom.xml添加几个依赖

       
            org.postgresql
            postgresql
            9.3-1102-jdbc4
       

       
            org.apache.tomcat
            tomcat-jdbc
            8.0.9
       

2、创建jdbc.properties配置文件

ticket.database.driver =  org.postgresql.Driver
ticket.database.url = jdbc:postgresql://***.dev.cn6.qunar.com:5433/check_result
ticket.database.username = menpiao_dev
ticket.database.password = ***-***-***

3、在dispatcher-servlet.xml里添加数据源

            destroy-method="close" autowire="no">
       
       
       
       
       
       
       
       
       
       
       
       
       
       
   

4、创建测试Service类

package com.qunar.check.Service;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestService {
    public void test() {
        try {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("dispatcher-servlet.xml");
            DataSource ds = ctx.getBean("dataSource", DataSource.class);
            Connection conn = ds.getConnection();
            Statement st = conn.createStatement();
            ResultSet rt = st.executeQuery("select * from datasource");
            while (rt.next()) {
                String test1 = rt.getString(2);
                System.out.println(test1);
            }
            rt.close();
            st.close();
            conn.close();
        } catch (Exception e) {
            System.out.println(e);
        } finally {
        }
    }
   
    public static void main(String args[]){
        TestService t = new TestService();
        t.test();
    }
}

5、测试:

INFO: Pre-instantiating singletons in : defining beans [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,testController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.view.InternalResourceViewResolver#0,dataSource]; root of factory hierarchy
一月 27, 2015 11:46:43 下午 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.do] onto handler [com.qunar.check.Controller.TestController@75be5b6]
test

下载地址:

------------------------------------------分割线------------------------------------------

免费下载地址在

用户名与密码都是

具体下载目录在 /2015年资料/2月/8日/Spring MVC 链接 PostgreSQL/

下载方法见

------------------------------------------分割线------------------------------------------

下面的文章您可能也喜欢

CentOS 6.3环境下yum安装PostgreSQL 9.3

PostgreSQL缓存详述

Windows平台编译 PostgreSQL

Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)环境的配置与安装

Ubuntu上的phppgAdmin安装及配置

CentOS平台下安装PostgreSQL9.3

PostgreSQL配置Streaming Replication集群

如何在CentOS 7/6.5/6.4 下安装PostgreSQL 9.3 与 phpPgAdmin 

------------------------------------------分割线------------------------------------------

PostgreSQL 的详细介绍:请点这里
PostgreSQL 的下载地址:请点这里

本文永久更新链接地址:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Master the key concepts of Spring MVC: Understand these important features Master the key concepts of Spring MVC: Understand these important features Dec 29, 2023 am 09:14 AM

Understand the key features of SpringMVC: To master these important concepts, specific code examples are required. SpringMVC is a Java-based web application development framework that helps developers build flexible and scalable structures through the Model-View-Controller (MVC) architectural pattern. web application. Understanding and mastering the key features of SpringMVC will enable us to develop and manage our web applications more efficiently. This article will introduce some important concepts of SpringMVC

Java backend development: API MVC framework development using Java Spring MVC Java backend development: API MVC framework development using Java Spring MVC Jun 17, 2023 am 10:27 AM

Java backend development is a very important technology that is at the core of modern Internet applications. Java backend development mainly involves APIMVC framework development. In this article, I will introduce how to use JavaSpringMVC for APIMVC framework development. JavaSpringMVC is a very powerful open source framework, which is mainly used for the development of web applications. It uses the MVC (Model-View-Controller) architectural model

The role of the controller package in java The role of the controller package in java May 07, 2024 am 02:45 AM

In the Spring MVC architecture, the Controller package implements business logic by processing user requests and returning responses. Its responsibilities include: receiving user requests (usually via HTTP). Validate and process request parameters. Call the appropriate business logic (usually the service layer). Render the view and return it to the user (usually HTML, JSON, or XML).

JAX-RS vs. Spring MVC: A battle between RESTful giants JAX-RS vs. Spring MVC: A battle between RESTful giants Feb 29, 2024 pm 05:16 PM

Introduction RESTful APIs have become an integral part of modern WEB applications. They provide a standardized approach to creating and using Web services, thereby improving portability, scalability, and ease of use. In the Java ecosystem, JAX-RS and springmvc are the two most popular frameworks for building RESTful APIs. This article will take an in-depth look at both frameworks, comparing their features, advantages, and disadvantages to help you make an informed decision. JAX-RS: JAX-RSAPI JAX-RS (JavaAPI for RESTful Web Services) is a standard JAX-RSAPI developed by JavaEE for developing REST

Spring Security permission control framework usage guide Spring Security permission control framework usage guide Feb 18, 2024 pm 05:00 PM

In back-end management systems, access permission control is usually required to limit different users' ability to access interfaces. If a user lacks specific permissions, he or she cannot access certain interfaces. This article will use the waynboot-mall project as an example to introduce how common back-end management systems introduce the permission control framework SpringSecurity. The outline is as follows: waynboot-mall project address: https://github.com/wayn111/waynboot-mall 1. What is SpringSecurity? SpringSecurity is an open source project based on the Spring framework, aiming to provide powerful and flexible security for Java applications.

What is the difference between the architecture of the Spring WebFlux framework and traditional Spring MVC? What is the difference between the architecture of the Spring WebFlux framework and traditional Spring MVC? Apr 17, 2024 pm 02:36 PM

The key difference between SpringWebFlux and SpringMVC is reactive programming (asynchronous processing) and blocking I/O model. This difference leads to key architectural differences: asynchronous processing and event loop models; handlers based on functional interfaces; asynchronous response streams (Publisher objects); simplified exception handling mechanisms; higher throughput and scalability.

Go language versus Java: Comparison from features to applications Go language versus Java: Comparison from features to applications Apr 08, 2024 pm 02:45 PM

The main differences between Go and Java are the type system, concurrency and memory management. Go uses a static type system, which forces types to be declared at compile time, while Java uses a semi-static type system, which allows types to be inferred at runtime. Go's Goroutine supports high concurrency, while Java uses Java threads and locking mechanisms. Go uses a garbage collector to automatically manage memory, while Java requires explicit management of certain resources. These differences lead to different application scenarios: Go is suitable for high-concurrency web services, cloud computing, and big data, while Java is suitable for enterprise-level applications that require complexity and stability.

The development history of Java architecture: from J2EE to SpringBoot The development history of Java architecture: from J2EE to SpringBoot Feb 02, 2024 pm 04:02 PM

Java architecture is a programming language widely used in enterprise application development. With the continuous advancement of technology and changing development needs, the Java architecture has also undergone multiple evolutions and developments. This article will explore the evolution and development of Java architecture from J2EE to SpringBoot. J2EE era J2EE (Java2Platform, Enterprise Edition) is an important milestone in Java architecture, launched in 1999. It provides a set of standards

See all articles