www.pudn.com > ImageRe.rar > DataConnection.java


package com.image.data; 
 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.SQLException; 
import java.util.Properties; 
 
 
public class DataConnection { 
	 
	public static Connection getConnection() throws SQLException, IOException,ClassNotFoundException{   
        Properties props = new Properties(); 
        FileInputStream in = new FileInputStream("database.properties"); 
        props.load(in); 
        in.close(); 
 
        String drivers = props.getProperty("jdbc.drivers"); 
        if (drivers != null)  
        	System.setProperty("jdbc.drivers", drivers); 
         
        Class.forName("com.mysql.jdbc.Driver");  
 
        String url = props.getProperty("jdbc.url"); 
        String username = props.getProperty("jdbc.username"); 
        String password = props.getProperty("jdbc.password"); 
 
        return DriverManager.getConnection(url, username, password); 
    } 
 
}