Java数据库编程技术 第七章习题

本文主要探讨了Java数据库编程技术,详细讲解了第七章的习题,涵盖了JDBC连接、SQL查询、数据操作等方面,旨在帮助读者深入理解并实践Java与数据库的交互技巧。

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

package com.car.dao;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

import com.car.pojo.Car;


public class BaseDao {
	
	private static  String driver = null;
	private static  String url = null;
	private static  String userName = null;
	private static  String password = null;
	private static final String resource = "database.properties";
	protected Connection conn = null;
	protected PreparedStatement ps = null;
	ResultSet rs = null;

	public void setRs(ResultSet rs) {
		this.rs = rs;
	}

	static{
		InputStream in = BaseDao.class.getClassLoader().getResourceAsStream(resource);
		Properties properties = new Properties();
		try {
			properties.load(in);
			driver = properties.getProperty("jdbc.driver");
			url = properties.getProperty("jdbc.url");
			userName = properties.getProperty("jdbc.userName");
			password = properties.getProperty("jdbc.password");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	
	public static Connection getConnection() throws Exception{
		//1.加载驱动
		Class.forName(driver);
		//2.获取连接
		Connection connection =  DriverManager.getConnection(url, userName, password);
		return connection;
	}
	
	public static void release(Connection conn,PreparedStatement ps,ResultSet rs) throws Exception{
		if(conn!=nu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值