This content has been marked as final. Show 6 replies
Please read Tomcat documentation:
Thank you for getting back. But the link doesnt mention anything about the Eclipse IDE and how we can connect to the database in eclipse. I am using Eclipse IDE and need info on where to keep jar files and stuff.
Please help me out.
Just put the Oracle JAR's in the classpath (build path) of the project and write JDBC/DAO code accordingly.
If you want to connect from jsp, the only thing you need is a connection object.
I will provide you the steps
1) DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
--->the above statement is common no changes rquired.
2) Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@hostname:1526:orcl", "scott", "tiger");
// @machineName:port:SID, userid, password
--->type "select * from global_name" in oracle you will get a string as an output
--->copy the first word before the first dot
---> in the above statement change the "orcl" witht he word you have copied.
-->change the username scott with your oracle username and tiger with your oracle password
Statement stmt = conn.createStatement();
--> the above is to create the statement object which will be usefull to
-->send sql query to the oracle database
ResultSet rset = stmt.executeQuery("select * from emp");
-->the above statement executes the query and the whole table is
-->stored inthe ResultSet object
System.out.println (rset.getString(1)); // Print col 1
--->the above statement is to loop through the resultset object and get the first column data and print it in the console.
if you want to get other columns you can use rset.getString(2);rset.getString(3) and soo on.
-->the above is used to close the statement.
Also make sure to pu the "classes111.zip" it will be located in the classpath "D:\oracle\ora81\jdbc\lib"
you can do it in the system environment vaiable
or you can put the zip file in "....\Tomcat 5.0\common\lib folder. It will be automatically picked up by the eclipse IDE
hope it will be clear enough
Message was edited by:
hello peter,Everything is there. This documentation is IDE independent. You should: (quote form tutorial):
Thank you for getting back. But the link
doesnt mention anything about the Eclipse IDE and
how we can connect to the database in eclipse. I am
using Eclipse IDE and need info on where to keep jar
files and stuff.
lease help me out.
For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release. Copy the Oracle JDBC jar to $CATALINA_HOME/lib, where CATALINA_HOME is a path in you're tomcat installation.
2) server.xml configuration, add:
<Resource name="jdbc/myoracle" auth="Container"
username="scott" password="tiger" maxActive="20" maxIdle="10"
where you need to change:
- url - is url in "oracle style", change it
All possible options are listed here: http://jakarta.apache.org/commons/dbcp/configuration.html
3) Code example:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
Connection con = ds.getConnection();
String query = "SELECT * FROM students WHERE UserLogin=?";
PreparedStatement prepStmt = con.prepareStatement(query);
ResultSet rs = prepStmt.executeQuery();
Thank you for your response. I got it working now, but dint have to change anything in the server.xml or web.xml
I just had to include ojdbc14.jar file in my project's java build path in eclipse. Thats it. It worked.