CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Java

 how to connect oracle database using jsp

Print topic Send  topic

Author Message
shirisha19

Posts: 7
Posted: 08/27/2005, 5:07 AM



hi

i want the code for connecting database using jsp.we are tried it
but connetion object is not created.we tried like this

<%@ page import = "java.sql.*"%>
<%@ page import = "java.io.*"%>

<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.println("hello" );
Connection con = DriverManager.getConnection("jdbc:odbc:reg","scott","tiger");
out.println("hello java world" +con);
String name = request.getParameter( "username" );
out.println("hello "+name);
session.setAttribute( "theName", name );
out.println("hello");
con.close();

}catch(Exception e)
{
e.printStackTrace();
System.out.println("exception occured"+e);
}
%>
and html page is

<HTML>
<BODY>
<FORM METHOD=POST ACTION="SaveName.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
after executing this we are getting only one print statement before creating connection.
please help me.....................
View profile  Send private message
shirisha19

Posts: 7
Posted: 08/30/2005, 1:18 AM

we got sol by createing sys dsn.
View profile  Send private message
sandeep
Posted: 10/19/2005, 3:58 AM

Current System
eserver221
Posted: 10/19/2005, 6:23 PM

This is an excerpt from my workable jsp, copy & paste:

<%@page contentType="text/html; charset=GBK"%>
<%@page import="java.sql.*,java.io.*,java.text.*,java.util.*,custom.Myfmt" %>
<%
String driver = application.getInitParameter("jdbc.driver");
String url = application.getInitParameter("jdbc.url");
String usr = application.getInitParameter("usr");
String ps = application.getInitParameter("passwd");

//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Class.forName(driver);
Connection conn = DriverManager.getConnection (url, usr, ps);
Statement stmt = conn.createStatement ();
eserver221
Posted: 10/19/2005, 6:27 PM

Also, you should put the following into web.xml in WEB-INF:

<context-param>
<param-name>jdbc.driver</param-name>
<param-value>oracle.jdbc.OracleDriver</param-value>
<description>
Full class name of the JDBC driver to be used.
</description>
</context-param>

<context-param>
<param-name>jdbc.url</param-name>
<param-value>jdbc:oracle:oci8:@ocean</param-value>
<description>
The JDBC URL used to connect to the ora9idb
</description>
</context-param>

<context-param>
<param-name>usr</param-name>
<param-value>potato</param-value>
</context-param>

<context-param>
<param-name>passwd</param-name>
<param-value>potato</param-value>
</context-param>


Give it a try, good luck!
saikat
Posted: 11/22/2005, 3:13 PM

Quote :
hey guys im giving u code to connecting , displaying , inserting to oracle database...

:-):-):-):-):-):-):-):-):-):-)
import java.sql.*;

public class TestDb
{
private Connection con;
private PreparedStatement ps;
private ResultSet rs;

public void connect(String dsn,String user,String pass)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:"+dsn,user,pass);
System.out.println("Connected.");
}
catch(Exception e)
{
System.out.println(e);
}
}

public void display(String tab)
{
try
{
ps = con.prepareStatement("select * from "+tab);
rs = ps.executeQuery();
int count = 0;
while(rs.next())
{
System.out.println("Name :: "+rs.getString(1)+" , Age :: "+rs.getString(2)+" , Phone no :: "+rs.getString(3));
count++;
}
System.out.println(count+" records selected...");
}
catch(Exception e)
{
System.out.println(e);
}
}

public void insert(String tab,String name,String age,String ph)
{
try
{
ps = con.prepareStatement("insert into "+tab+" values ( ? , ? , ?)");
ps.setString(1,name);
ps.setString(2,age);
ps.setString(3,ph);
//ps.executeUpdate();
ps.executeUpdate();
System.out.println("One record inserted into database...");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
saikat
Posted: 11/22/2005, 3:19 PM

:-):-):-):-)O:)O:)O:)O:)O:)O:)O:):-)

The table should have following 3 fields

1 . Name (Varchar)
2. Age (Varchar)
3. Phno (Varchar)

Now just create the dsn,and an object of TestDb class and call it.
Please do nesessary changes to print messages in jsp pages.....
satya gopal
Posted: 11/28/2005, 12:42 AM

how to connect oracle database using jsp
Aqeel Aljadi
Posted: 12/26/2005, 12:45 AM

hi there

i have oracle application with 9i database and i want to view some field from that database in my web page so whats the easiest way to do this and how ... tell me step by step cuz i just start now learning this things .... what should i do to make the view by a primary key to get the result .



thnx
aftab
Posted: 02/02/2006, 3:44 AM

how to connect microsoft access database using jsp?
&How can i create a html page for this.......
matheus

Posts: 386
Posted: 02/02/2006, 8:56 AM

Go to a specific Java's forum. Here is Java's forum WITH Codecharge.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
aftab
Posted: 02/07/2006, 12:02 AM

How can i import java files into a jsp????
Gopi
Posted: 02/10/2006, 1:17 AM

Hi,

And i want to know how to insert the values in the Database.
Pls.let me know.Please go thru the code.Whether that INSERT QUERY is correct or not and i want to know how to call the doInsert() method in the InsertBean.java .




InsertBean.java
package dk.bestseller.bestinfoII.util.jsp;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class InsertBean implements Serializable {
private static String dbURL = "jdbc:oracle:oci8:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST = 10.45.0.184)(PORT=1526)))(CONNECT_DATA=(SID=ERPDEV2)))";
private static String usr_id = "developer";
private static String pwd = "betty";
private String dbDriver = "oracle.jdbc.driver.OracleDriver";
private Connection dbCon;
int repid;
int repriorid;
String repname; --> Here i removed the null
String repfilename;
String del;
String creby;
String creon;
String chby;
String chon;
public InsertBean() {
super();
}
public int getRepId() {
return this.repid;
}
public void setRepId(int repid) {
this.repid = repid;
}
public int getRepriorid() {
return this.repriorid;
}
public void setRepriorid(int repriorid) {
this.repriorid = repriorid;
}
public String getRepName() {
return this.repname;
}
public void setRepName(String repname) {
this.repname = repname;
}
public String getRepFileName() {
return this.repfilename;
}
public void setRepFileName(String repfilename) {
this.repfilename = repfilename;
}
public String getDeleted() {
return this.del;
}
public void setDeleted(String del) {
this.del = del;
}
public String getCreatedby() {
return this.creby;
}
public void getCreatedby(String creby) {
this.creby = creby;
}
public String getCreatedon() {
return this.creon;
}
public void setCreatedon(String creon) {
this.creon = creon;
}
public String getChangedby() {
return this.chby;
}
public void setChangedby(String chby) {
this.chby = chby;
}
public String getChangedon() {
return this.chon;
}
public void setChangedon(String chon) {
this.chon = chon;
}
public void doInsert() throws ClassNotFoundException,SQLException {
Class.forName(dbDriver);
dbCon = DriverManager.getConnection(dbURL,usr_id,pwd);
Statement s = dbCon.createStatement();

String sql = "INSERT INTO reports_test(REPORT_ID,REPORT_PRIOR_ID,REPORT_NAME,REPORT_FILE_NAME,DELETED,CREATED_BY,CREATED_ON,CHANGED_BY,CHANGED_ON) values ('" + this.repid; sql = sql + "'," + repriorid; sql = sql + "'," + repname; sql = sql +"'," + repfilename; sql = sql + "'," + del; sql = sql + "',"+ creby;sql=sql + "'," +creon;sql=sql + "'," + chby;sql=sql+ "'," +chon;sql=sql+ ")";
int insertResult = s.executeUpdate(sql);
dbCon.commit();
dbCon.close();
}
}
Input
REPORT ID: 37
REPORT PRIOR ID: 31
REPORT NAME: ReportStatistic
REPORT FILE NAME: ReportsSelectReportStatisticIFrame.jsp
DELETED: N
CREATED BY: go
CREATED ON: 21
CHANGED BY: pi
CHANGED ON: 14
output
******
You entered
REPORT ID: 37
REPORT PRIOR ID: 31
REPORT NAME: ReportStatistic
REPORT FILE NAME: ReportsSelectReportStatisticIFrame.jsp
DELETED: null --> Please let me know why it is happening I was enetering all the values.But why it gives NULL values
CREATED BY: null
CREATED ON: null
CHANGED BY: null
CHANGED ON: null









matheus

Posts: 386
Posted: 02/10/2006, 2:50 AM

Go to a specific Java's forum. Here is Java's forum WITH Codecharge.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
Mathew
Posted: 02/21/2006, 3:11 AM

Hi, This is a wonderful forum with lot many qustions and answers..Its very much helpful for beginers like us...Thanks a lot
enigma
Posted: 03/01/2006, 12:34 AM

Hi,
can i have more examples of interaction between JSP and oracles

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.