Help Connecting lift to an Oracle Database
So I have something like this in my boot.scala:
object DBVendor extends ConnectionManager {
def newConnection(name: ConnectionIdentifier)开发者_StackOverflow中文版: Box[Connection] = {
try {
Class.forName("oracle.jdbc.driver.OracleDriver")
val dm = DriverManager.getConnection("jdbc:oracle:thin:@hostname:1521:orcl", "username", "password");
Full(dm)
} catch {
case e : Exception => e.printStackTrace; Empty
}
}
def releaseConnection(conn: Connection) {conn.close}
}
Couple quick questions I have are... How do I set up the driver to connect?
the @hostname from what I see has been for local databases but mine is remote... I have all the information to connect to it through the sqldeveloper I use and figured that all that I would need is the hostname there.
Is the hostname all that needs to go there if thats all I needed? or will I been in need of some kind of absolute address?As long as the machine running the code can see the hostname (which you can test with a simple ping), that's all you need.
You will need the appropriate oracle jdbc driver in the path for the Java to find. You can get the latest drivers from downloads.oracle.com
You will need to change "hostname" by the server's IP Address (As Gary says, if You don't know the IP Address You can test with "ping hostname").
In Lift, the default path for the JDBC's driver is
%Your project's path%/src/main/webapp/WEB-INF/lib
Probably, you have to create the lib's folder. If You have an Oracle's Client installed, you can copy the appropiate driver from:
%your oracle's client path%/jdbc/lib
The @hostname in the connection string represents the hostname of the physical machine that hosts the database. The hostname of the database host along with its IP address should be in your Operating System's hosts file. You can also use hardcoded IP address in the connection string. The @hostname does not refer to to your "local database". If the client application runs on the same server that hosts the database you can use @localhost in the connection string. orcl represents an oracle service. This info should be provided by your database administrator.
Also check this link out: http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-oracle-server-using-jdbc-4.html
精彩评论