how to Deal with data base in java

本文介绍了几种常用的数据库操作工具和技术,包括直接使用JDBC进行数据库访问的方法、利用Spring JDBC模板简化数据库操作的方式,以及采用Spring JPA实现更为简洁高效的数据库交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

We have many tool to deal with database, as giant Hibernate , famous Spring JDBC template , Spring Jpa , there are  too many that , en , I can't mention all .

 

at first we use JDBC , haha , just like something belove code, quit a lot code 

 

Connection con= null;

PreparedStatement pStmt=null;

ResultSet rs = null;

try{          

            con = ods.getConnection();

            String sql = "select * from admin";

            pStmt=con.prepareStatement(sql);           

            rs=pStmt.executeQuery();

            while(rs.next())

            {            }

}

catch(Exception ex) {

try{

         con.rollback();

    }catch(SQLException sqlex){

          sqlex.printStackTrace(System.out);

     }

     ex.printStackTrace();

}finally{

   try{

            rs.close();

            pStmt.close();

            con.close();

   }catch(Exception e){e.printStackTrace();}

}

 

 

and then Spring JDBC template

 

String sql = "select * from admin";

jdbcTemplate.query(sql,new RowCallbackHandler() {

         public void processRow(ResultSet rs) throws SQLException {   

                }

            } );

 

 

 

Spring Jpa, this example require JDK1.5+

@Repository
@Transactional
public class ArticleColumnDaoImpl implements ArticleColumnDao {
        @PersistenceContext
    private EntityManager entityManager;

    public ArticleColumn getByid(long id) {
        return entityManager.find(ArticleColumn.class,id); 
    }

    public List<ArticleColumn> getbylayer(long layer) {
        return entityManager.createQuery("select a from ArticleColumn a where a.layer =:layer").setParameter("layer",layer).getResultList();
    }
     public void addArticlekind(ArticleColumn articlekind) {
        entityManager.persist(articlekind);
    }

    public void deleteArticlekind(long id) {
      ArticleColumn articlekind=entityManager.find(ArticleColumn.class,id);
      entityManager.remove(articlekind);
    }

    public void mergeArticlekind(ArticleColumn articlekind) {
       entityManager.merge(articlekind);
    }
}
 

this Jpa is quite like Hibernate , but something easier to code.

 

 

 

内容概要:本文详细介绍了900W或1Kw,20V-90V 10A双管正激可调电源充电机的研发过程和技术细节。首先阐述了项目背景,强调了充电机在电动汽车和可再生能源领域的重要地位。接着深入探讨了硬件设计方面,包括PCB设计、磁性器件的选择及其对高功率因数的影响。随后介绍了软件实现,特别是程序代码中关键的保护功能如过流保护的具体实现方法。此外,文中还提到了充电机所具备的各种保护机制,如短路保护、欠压保护、电池反接保护、过流保护和过温度保护,确保设备的安全性和可靠性。通讯功能方面,支持RS232隔离通讯,采用自定义协议实现远程监控和控制。最后讨论了散热设计的重要性,以及为满足量产需求所做的准备工作,包括提供详细的PCB图、程序代码、BOM清单、磁性器件和散热片规格书等源文件。 适合人群:从事电力电子产品研发的技术人员,尤其是关注电动汽车充电解决方案的专业人士。 使用场景及目标:适用于需要高效、可靠充电解决方案的企业和个人开发者,旨在帮助他们快速理解和应用双管正激充电机的设计理念和技术要点,从而加速产品开发进程。 其他说明:本文不仅涵盖了理论知识,还包括具体的工程实践案例,对于想要深入了解充电机内部构造和工作原理的人来说是非常有价值的参考资料。
/****************************************************************************** * * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the Xilinx shall not be used * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * ******************************************************************************/ /*****************************************************************************/ /** * @file xttcps_rtc_example.c * * This example uses one timer/counter to make a real time clock. The number of * minutes and seconds is displayed on the console. * * * @note * * <pre> * MODIFICATION HISTORY: * * Ver Who Date Changes * ---- ------ -------- --------------------------------------------- * 1.00 drg/jz 01/23/10 First release * 3.01 pkp 01/30/16 Modified SetupTimer to remove XTtcps_Stop before TTC * configuration as it is added in xttcps.c in * XTtcPs_CfgInitialize * 3.2 mus 10/28/16 Updated TmrCntrSetup as per prototype of * XTtcPs_CalcIntervalFromFreq * ms 01/23/17 Modified xil_printf statement in main function to * ensure that "Successfully ran" and "Failed" strings * are available in all examples. This is a fix for * CR-965028. *</pre> ******************************************************************************/ /***************************** Include Files *********************************/ #include <stdio.h> #include <stdlib.h> #include "xparameters.h" #include "xstatus.h" #include "xil_io.h" #include "xil_exception.h" #include "xttcps.h" #include "xscugic.h" #include "xil_printf.h" /************************** Constant Definitions *****************************/ /* * The following constants map to the XPAR parameters created in the * xparameters.h file. They are only defined here such that a user can easily * change all the needed parameters in one place. */ #define TTC_TICK_DEVICE_ID XPAR_XTTCPS_0_DEVICE_ID #define TTC_TICK_INTR_ID XPAR_XTTCPS_0_INTR #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID /* * Constants to set the basic operating parameters. * PWM_DELTA_DUTY is critical to the running time of the test. Smaller values * make the test run longer. */ #define TICK_TIMER_FREQ_HZ 100 /* Tick timer counter's output frequency */ #define TICKS_PER_CHANGE_PERIOD TICK_TIMER_FREQ_HZ /* Tick signals per update */ /**************************** Type Definitions *******************************/ typedef struct { u32 OutputHz; /* Output frequency */ XInterval Interval; /* Interval value */ u8 Prescaler; /* NO USED */ u16 Options; /* Option settings */ } TmrCntrSetup; /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ static int TmrRtcInterruptExample(void); /* Main test */ /* Set up routines for timer counters */ static int SetupTicker(void); static int SetupTimer(int DeviceID); /* Interleaved interrupt test for both timer counters */ static int WaitForDutyCycleFull(void); static int SetupInterruptSystem(u16 IntcDeviceID, XScuGic *IntcInstancePtr); static void TickHandler(void *CallBackRef); /************************** Variable Definitions *****************************/ static XTtcPs TtcPsInst; /* Timer counter instance */ static TmrCntrSetup SettingsTable= {TICK_TIMER_FREQ_HZ, 0, 0, 0}; /* Ticker timer counter initial setup, only output freq */ XScuGic InterruptController; /* Interrupt controller instance */ static u8 ErrorCount; /* Errors seen at interrupt time */ static volatile u8 UpdateFlag; /* Flag to update the seconds counter */ static u32 TickCount; /* Ticker interrupts between seconds change */ /*****************************************************************************/ /** * * This is the main function that calls the TTC RTC interrupt example. * * @param None * * @return * - XST_SUCCESS to indicate Success * - XST_FAILURE to indicate a Failure. * * @note None. * *****************************************************************************/ int main(void) { int Status; xil_printf("Starting Timer RTC Example"); Status = TmrRtcInterruptExample(); if (Status != XST_SUCCESS) { xil_printf("ttcps rtc Example Failed\r\n"); return XST_FAILURE; } xil_printf("Successfully ran ttcps rtc Example\r\n"); return XST_SUCCESS; } /*****************************************************************************/ /** * * This is the main function of the interrupt example. * * * @param None. * * @return XST_SUCCESS to indicate success, else XST_FAILURE to indicate * a Failure. * ****************************************************************************/ static int TmrRtcInterruptExample(void) { int Status; /* * Make sure the interrupts are disabled, in case this is being run * again after a failure. */ /* * Connect the Intc to the interrupt subsystem such that interrupts can * occur. This function is application specific. */ Status = SetupInterruptSystem(INTC_DEVICE_ID, &InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set up the Ticker timer */ Status = SetupTicker(); if (Status != XST_SUCCESS) { return Status; } Status = WaitForDutyCycleFull(); if (Status != XST_SUCCESS) { return Status; } /* * Stop the counters */ XTtcPs_Stop(&TtcPsInst); return XST_SUCCESS; } /****************************************************************************/ /** * * This function sets up the Ticker timer. * * @param None * * @return XST_SUCCESS if everything sets up well, XST_FAILURE otherwise. * *****************************************************************************/ int SetupTicker(void) { int Status; TmrCntrSetup *TimerSetup; XTtcPs *TtcPsTick; TimerSetup = &SettingsTable; /* * Set up appropriate options for Ticker: interval mode without * waveform output. */ TimerSetup->Options |= (XTTCPS_OPTION_INTERVAL_MODE); /* * Calling the timer setup routine * . initialize device * . set options */ Status = SetupTimer(TTC_TICK_DEVICE_ID); if(Status != XST_SUCCESS) { return Status; } TtcPsTick = &TtcPsInst; /* * Connect to the interrupt controller */ Status = XScuGic_Connect(&InterruptController, TTC_TICK_INTR_ID, (Xil_InterruptHandler)TickHandler, (void *)TtcPsTick); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the Timer counter */ XScuGic_Enable(&InterruptController, TTC_TICK_INTR_ID); /* * Enable the interrupts for the tick timer/counter * We only care about the interval timeout. */ XTtcPs_EnableInterrupts(TtcPsTick, XTTCPS_IXR_INT_ENABLE); /* * Start the tick timer/counter */ XTtcPs_Start(TtcPsTick); return Status; } /****************************************************************************/ /** * * This function uses the interrupt inter-locking between the ticker timer * counter and the waveform output timer counter. When certain amount of * interrupts have happened to the ticker timer counter, a flag, UpdateFlag, * is set to true. * * * @param None * * @return XST_SUCCESS if duty cycle successfully reaches beyond 100, * otherwise XST_FAILURE. * *****************************************************************************/ int WaitForDutyCycleFull(void) { u32 seconds; /* * Initialize some variables used by the interrupts and in loops. */ ErrorCount = 0; seconds = 0; /* * Loop until two minutes passes. */ while (seconds <= 121) { /* * If error occurs, disable interrupts, and exit. */ if (0 != ErrorCount) { return XST_FAILURE; } /* * The Ticker interrupt sets a flag for update. */ if (UpdateFlag) { /* * Calculate the time setting here, not at the time * critical interrupt level. */ seconds++; UpdateFlag = FALSE; xil_printf("Time: %d\n\r", seconds); } } return XST_SUCCESS; } /****************************************************************************/ /** * * This function sets up a timer counter device, using the information in its * setup structure. * . initialize device * . set options * . set interval and prescaler value for given output frequency. * * @param DeviceID is the unique ID for the device. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * *****************************************************************************/ int SetupTimer(int DeviceID) { int Status; XTtcPs_Config *Config; XTtcPs *Timer; TmrCntrSetup *TimerSetup; TimerSetup = &SettingsTable; Timer = &TtcPsInst; /* * Look up the configuration based on the device identifier */ Config = XTtcPs_LookupConfig(DeviceID); if (NULL == Config) { return XST_FAILURE; } /* * Initialize the device */ Status = XTtcPs_CfgInitialize(Timer, Config, Config->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the options */ XTtcPs_SetOptions(Timer, TimerSetup->Options); /* * Timer frequency is preset in the TimerSetup structure, * however, the value is not reflected in its other fields, such as * IntervalValue and PrescalerValue. The following call will map the * frequency to the interval and prescaler values. */ XTtcPs_CalcIntervalFromFreq(Timer, TimerSetup->OutputHz, &(TimerSetup->Interval), &(TimerSetup->Prescaler)); /* * Set the interval and prescale */ XTtcPs_SetInterval(Timer, TimerSetup->Interval); return XST_SUCCESS; } /****************************************************************************/ /** * * This function setups the interrupt system such that interrupts can occur. * This function is application specific since the actual system may or may not * have an interrupt controller. The TTC could be directly connected to a * processor without an interrupt controller. The user should modify this * function to fit the application. * * @param IntcDeviceID is the unique ID of the interrupt controller * @param IntcInstacePtr is a pointer to the interrupt controller * instance. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * *****************************************************************************/ static int SetupInterruptSystem(u16 IntcDeviceID, XScuGic *IntcInstancePtr) { int Status; XScuGic_Config *IntcConfig; /* The configuration parameters of the interrupt controller */ /* * Initialize the interrupt controller driver */ IntcConfig = XScuGic_LookupConfig(IntcDeviceID); if (NULL == IntcConfig) { return XST_FAILURE; } Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect the interrupt controller interrupt handler to the hardware * interrupt handling logic in the ARM processor. */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler) XScuGic_InterruptHandler, IntcInstancePtr); /* * Enable interrupts in the ARM */ Xil_ExceptionEnable(); return XST_SUCCESS; } /***************************************************************************/ /** * * This function is the handler which handles the periodic tick interrupt. * It updates its count, and set a flag to signal PWM timer counter to * update its duty cycle. * * This handler provides an example of how to handle data for the TTC and * is application specific. * * @param CallBackRef contains a callback reference from the driver, in * this case it is the instance pointer for the TTC driver. * * @return None. * *****************************************************************************/ static void TickHandler(void *CallBackRef) { u32 StatusEvent; /* * Read the interrupt status, then write it back to clear the interrupt. */ StatusEvent = XTtcPs_GetInterruptStatus((XTtcPs *)CallBackRef); XTtcPs_ClearInterruptStatus((XTtcPs *)CallBackRef, StatusEvent); if (0 != (XTTCPS_IXR_INT_ENABLE & StatusEvent)) { TickCount++; if (TICKS_PER_CHANGE_PERIOD == TickCount) { TickCount = 0; UpdateFlag = TRUE; } } else { /* * The Interval event should be the only one enabled. If it is * not it is an error */ ErrorCount++; } } 请详细分析一下以上的代码,并给出详细的解释
05-20
### 关于Xilinx TTCPS RTC中断示例代码的功能与结构 #### 功能概述 该代码片段定义了一组宏用于配置定时器设备及其频率参数,主要用于初始化和操作基于Xilinx Zynq SoC平台上的TTC(Triple Timer Counter Peripheral Subsystem)模块。通过这些宏定义,可以指定使用的硬件资源以及相关的中断ID[^1]。 #### 结构解析 以下是代码的关键部分及其实现细节: 1. **设备标识符** 宏`TIMER_DEVICE_ID`被设置为`FPAR_TTCPS_0_DEVICE_ID`,这表明程序将使用Zynq片上系统中的第一个TTC外设实例作为计时源。此常量通常由Xilinx工具链自动生成,并映射到具体硬件地址空间内的特定寄存器集合[^1]。 2. **工作频率设定** `TIMER_FREQ`变量提供了两个可能的工作频率选项——一个是大约55 MHz (`0x34FB5E3`) ,另一个接近333 MHz(`0x13DE4355`) 。实际应用中应依据设计需求选取合适的数值来满足精度与时序约束条件[^1]。 3. **中断向量表入口** 使用了名为`TIMER_IRPT_INTR_ID` 的宏表示当触发定时事件时所关联的CPU异常处理机制编号即中断号。它指向预定义好的中断服务子程序位置以便响应来自选定定时单元的通知信号[^1]。 4. **内存区域分配说明 (附加信息)** 另一段独立但有关联性的描述涉及到了嵌入式系统的存储布局规划方面。其中指定了RAM区间的起始结束边界分别为`0x4000000` 和 `0x4FFFFFF`, 这对于加载执行应用程序至关重要因为它们限定了可用物理地址范围从而影响数据放置策略[^2]. 5. **开发环境搭建指南(补充材料)** 提供了一个简短流程介绍如何利用 Xilinx SDK 创建针对目标板卡定制化的软件项目框架, 包含导出HDF文件步骤以及启动调试环节等内容[^3]. 6. **网络层协议简介(扩展阅读)** 同样也提及了一些基础计算机通讯概念比如TCP/IP模型里的传输控制协议(TCP),虽然这部分内容看似偏离主题较远但它可以帮助理解整个计算生态系统是如何协同工作的[^4]. 综上所述,上述代码主要服务于实时操作系统或者专用固件构建过程中涉及到的时间管理组件初始化阶段;同时配合恰当的链接脚本完成全局资源配置过程。 ```c #define TIMER_DEVICE_ID XPAR_TTCPS_0_DEVICE_ID // 设定要使用的定时器外围设备 ID [^1] #define TIMER_FREQ 0x34FB5E3 // 设置默认运行频率约为 55Mhz [^1] // 中断控制器相关配置项 #define TIMER_IRPT_INTR_ID XPAR_INTC_0_TTCPS_0_INTERRUPT_INTR /* Example of Memory Map Definition */ define symbol __ICFEDIT_region_RAM_start__ = 0x4000000; define symbol __ICFEDIT_region_RAM_end__ = 0x4FFFFFF; [^2] /* Steps to Setup Development Environment with Xilinx Tools*/ /* Export HDF File -> Launch SDK Toolchain -> Create Bare Metal Project */ [^3] /* Basic Knowledge About Communication Protocols Like TCP */ /* Reliable Connection-Oriented Protocol Suitable For Data Transfer Applications Such As Web Browsing And Email Services. */ [^4] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值