Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cts.mage.connection;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.Properties;
- public class DBConnection {
- public static Connection getConnection(){
- Connection conn=null;
- InputStream is = null;
- Properties prop = null;
- prop = new Properties();
- try {
- is = new FileInputStream(new File("f:\\mylan\\dbconfig.properties"));
- prop.load(is);
- String db = prop.getProperty("db");
- String url = prop.getProperty("url");
- String username = prop.getProperty("username");
- String password = prop.getProperty("password");
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection((url+db),username,password);
- } catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return conn ;
- }
- }
- --------------dbconfig.properties
- url=jdbc:mysql://localhost:3306/
- db=mylan
- username=root
- password=root
Add Comment
Please, Sign In to add comment