|
|
Re: Build a webpage connectivity with oracle database using jsp [message #77266 is a reply to message #77245] |
Fri, 24 December 2004 10:23 |
vishwas
Messages: 2 Registered: July 2002
|
Junior Member |
|
|
First, make sure your web server is configured to load the appropriate JDBC driver classes.
If you can't do that (because you're not the web administrator, for example),
you can do it from the page by writing the appropriate Class.forName
[<]%! Class.forName("my.appropriate.Driver"); %[>]
e.g. [<]%! Class.forName("oracle.jdbc.driver.OracleDriver");%[>]
Next, import the SQL classes in the page tag:
[<]%@ page ... import="java.sql.*" %">
e.g. [<]%@ page import="java.sql.*"%[>]
Then, create the database connection using the JSP declaration tag:
[<]%! Connection connection = DriverManager.getConnection(...) %[>]
e.g [<]%! Connection conn = DriverManager.getConnection("jdbcracle:thin:@testmachine:1521:SID", "scott", "tiger");%[>]
Finally, make a query and display the results:
[<]% Statement statement =
connection.createStatement();
ResultSet resultSet =
statement.executeQuery("select * from emp"); %[>]
The results are:
[<]% while (resultSet.next()) { %[>]
- [<]%= resultSet.getString(1) %[>]
[<]% } >
And that's it.
|
|
|
|