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

📄 myconn.java

📁 java版QQ聊天,实现用户登录验证
💻 JAVA
字号:
package com.net;

import java.sql.*;
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
import java.util.Properties;
import java.io.*;

public class myConn {
	
	public Connection conn ;
	public PreparedStatement ps ;
	
	public static void main(String args[]) {
		myConn PD = new myConn("db.ini");
	}
	
	public myConn(String LoadName)			//输入ini文件的名称LoadName
	{
		conn = null;
		ps = null;
		
		try{
			Properties prop = new Properties();
			//加载属性配置文件
			prop.load(new FileInputStream(LoadName));
		
		    //加载驱动
		    String driverClassName = prop.getProperty("driverClassName");
		   	Class.forName(driverClassName);
       
		    //注册驱动
		    String url = prop.getProperty("url");
		    String username = prop.getProperty("username");
		    String password = prop.getProperty("password");
		    
		    //获取连接
		    conn = DriverManager.getConnection(url,username,password);
		    

		}catch(FileNotFoundException e)
		{
			System.out.println(e);
			
		}catch(IOException e)
		{
			System.out.println(e);
		}catch(ClassNotFoundException e)
		{
			System.out.println(e);
			System.out.println("ClassNotFoundException");
		}catch(SQLException e)
		{
			System.out.println(e);
			System.out.println("SQLException");
		}
	}
			
	public Connection getConn()
	{
		return conn;
	}
	public PreparedStatement getPs()
	{
		return ps;
	}
}		

⌨️ 快捷键说明

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