Project

General

Profile

« Previous | Next » 

Revision 4080

Added by daigle about 16 years ago

Merge 1.9 changes into Head

View differences:

DBConnection.java
32 32

  
33 33
import org.apache.log4j.Logger;
34 34

  
35
import edu.ucsb.nceas.metacat.service.PropertyService;
36
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
37

  
35 38
/**
36 39
 * A class represent a connection object, it includes connection itself, 
37 40
 * index, status, age, createtime, connection time, usageCount, warning message
......
54 57
  private String checkOutMethodName;
55 58
  
56 59
  
57
  private static String  DBDriver=MetaCatUtil.getOption("dbDriver");
58
  private static String  DBConnectedJDBC=MetaCatUtil.getOption("defaultDB");
59
  private static String  userName=MetaCatUtil.getOption("user");
60
  private static String  passWord=MetaCatUtil.getOption("password");
60
  private static String  DBDriver;
61
  private static String  DBConnectedJDBC;
62
  private static String  userName;
63
  private static String  passWord;
64
  static {
65
		try {
66
			DBDriver=PropertyService.getProperty("database.driver");
67
			DBConnectedJDBC=PropertyService.getProperty("database.connectionURI");
68
			userName=PropertyService.getProperty("database.user");
69
			passWord=PropertyService.getProperty("database.password");
70
		} catch (PropertyNotFoundException pnfe) {
71
			System.err.println("Could not get property in static block: " 
72
					+ pnfe.getMessage());
73
		}
74
	}
75
  
61 76
  private static Logger logMetacat = Logger.getLogger(DBConnection.class);
62 77

  
63 78
  /**
......
355 370
     return connLocal;
356 371
  }//OpenDBConnection
357 372
  
373
  /** 
374
   * Method to test a JDBC database connection 
375
   *
376
   * @param dbDriver the string representing the database driver
377
   * @param connection the string representing the database connectin parameters
378
   * @param user name of the user to use for database connection
379
   * @param password password for the user to use for database connection
380
   */
381
  public static void testConnection(String dbDriver, String connection,
382
                String user, String password)
383
                throws SQLException
384
  {
385
     // Load the Oracle JDBC driver
386
     try
387
     {
388
       Class.forName (dbDriver);
389
     }
390
     catch (ClassNotFoundException e)
391
     {
392
       throw new SQLException(e.getMessage());
393
     }
394
     // Connect to the database
395
     Connection connLocal = null;
396
     connLocal = DriverManager.getConnection( connection, user, password);
397
     connLocal.close();
398
  }
399
  
358 400
  /**
359 401
   * Method to create a PreparedStatement by sending a sql statement
360 402
   * @Param sql, the sql statement which will be sent to db

Also available in: Unified diff