⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionfactory.java

📁 这是花卉管理的一个小型系统
💻 JAVA
字号:
package lib.nanjing.jdbc.util;

import java.sql.*;
import java.io.*;
import java.util.*;


public class ConnectionFactory {
	public static Connection getConnection() {
		// step 0 load the property file

		Properties prop = null;
		FileInputStream in = null;
		try {
			prop = new Properties();
			in = new FileInputStream("configuration/connect_info.conf");
			prop.load(in);
			in.close();
		} catch (FileNotFoundException fnf) {
			System.out.println("connect_info.conf file not found!!");
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

		// step 1 load(register) the driver

		String jdbcDriver = prop.getProperty("jdbc.drivers");
		try {
			Class.forName(jdbcDriver);
		} catch (ClassNotFoundException e) {
			System.out.println("load driver failure!!");
		}

		// step 2 establish connection to the database

		String url = prop.getProperty("jdbc.url");
		String user = prop.getProperty("jdbc.user");
		String password = prop.getProperty("jdbc.password");
		Connection con = null;
		try {
			con = DriverManager.getConnection(url, user, password);
			return con;
		} catch (SQLException e) {
			System.out.println("connect failure!!");
			return null;
		}
	}

	
	/*public static void main(String[] args){
		Connection con=ConnectionFactory.getConnection();
		Statement stat=null;
		
		try{
			stat=con.createStatement();
			System.out.println("create statement success!!");	
		}catch(SQLException e){
			e.printStackTrace();
			System.out.println("create statement failure!!");
		}
		
		//step 4 execute the SQL statement
		
		//step 5 process the result
		ResultSet results=null;
		try{
			results=stat.executeQuery("select * from salary");
			System.out.println("exceuteQuery success!!\nbegin to process the result >>>>>>>>>>>>>>>>");
			while(results.next()){
				System.out.print(results.getString("name")+'\t');
				System.out.print(results.getString("lev")+'\t');
				System.out.print(results.getString("salary")+'\t');
				System.out.println(results.getString("welfware"));
			}
		}catch(SQLException e){
			System.out.println("executeQuery failure!!");
		}
		//step 6 close the connection
		try{
			JdbcUtil.close(results,stat,con);
			System.out.println("connection closed success!!");
		}catch(Exception e){
			System.out.println("connection closed failure!!");
		}
	}*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -