JSP connection to Oracle
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Zhongjun_Luo
Posted On:   Friday, July 11, 2003 12:37 PM

I wrote following into JSP file: <%@ page import="java.sql.*" %> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection myConnection = DriverManager.getConnection("jdbc:odbc:Bac_Gene", "system", "system1"); System.out.println("Connection Successful"); Statement stmt = myConnection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT *" + "FROM REF_GENE_test"); while (rs.next()) { int TXSTART = rs.getInt ("TXSTART"); System.out.println("TXSTART = " + TXSTART); }//End of while loop myConnection.close();    More>>

I wrote following into JSP file:


<%@ page import="java.sql.*" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myConnection = DriverManager.getConnection("jdbc:odbc:Bac_Gene", "system", "system1");

System.out.println("Connection Successful");

Statement stmt = myConnection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT *" + "FROM REF_GENE_test");

while (rs.next())
{
int TXSTART = rs.getInt ("TXSTART");
System.out.println("TXSTART = " + TXSTART);
}//End of while loop

myConnection.close();
%>


When I open the web site, it does not show up
anything, does not give error message and even
"connection Successful".


If I change the code from


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection myConnection = DriverManager.getConnection("jdbc:odbc:Bac_Gene", "system", "system1");


to


DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@"+ "160.129.210.153" +":1521:BACWEB", "system","system1");
//Bac_Gene is DSN for BACWEB


When open the site, it gave:


type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
..............//more infor but not listed here
root cause
org.apache.jasper.JasperException: /BAC_GENE/BacGene.jsp(12,16) jsp.error.attribute.noequal
..............//more infor but not listed here


Could somebody recommend some suggestions. I appreciate
your help very much.

Zhongjun

   <<Less

Re: JSP connection to Oracle

Posted By:   hanspeter_schlapbach  
Posted On:   Sunday, July 13, 2003 11:52 PM



hi. here is some sample-code i once used to get access to an oracle-db. it is just thougt as a test, because it is not good practice to do such a thing within a jsp-page. of course it works.




some hints to following code (which you have to adapt for your own purposes):

    the classes111.zip (or whatever it is named) with oracle thin-driver has to be in classpath.


    you have to be sure, that oracle is listening on the specified port (1526 resp. 1521) and that there is no firewall locking this port in between.


    vsdb is the SID


    webview is username und password for the connecting user.


    phNr is value from the request (does not matter here)





maybe it helps


hanspeter schlapbach







...


int maxTS=0;


java.sql.Statement st;


java.sql.ResultSet rs;


java.sql.Connection db=null;


// connect to database


// open oracle-db


try {


Class.forName("oracle.jdbc.driver.OracleDriver");


db = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@172.16.200.102:1526:vsdb", "webview", "webview");


}


catch(Exception e) {


System.err.println("Error connecting to DB:" + e.getMessage());


}


try {


st = db.createStatement();


//max. timestamp bestimmen:


sqlStmt= " select max(timestamp) as timestamp from dbmgr.v_z15min_einaus where parkhaus= ";


sqlStmt= sqlStmt + phNr;


if (debug == true) out.println(">"+sqlStmt+"<
");


rs = st.executeQuery(sqlStmt);


while (rs.next()) {


maxTS= rs.getInt("timestamp");


if (debug == true) {


out.println("maxTS:");


out.println(maxTS);


out.println("
");


}


}//end while


About | Sitemap | Contact