aspose file tools*
The moose likes JDBC and the fly likes Access to the Oracle database using Java Applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Access to the Oracle database using Java Applets" Watch "Access to the Oracle database using Java Applets" New topic
Author

Access to the Oracle database using Java Applets

Bharat Agarwal
Greenhorn

Joined: Jun 16, 2001
Posts: 21
HI,
I am trying to connect the applet with the oracle database... I have tried using all different tactics....and it is giving me different problems all the time....CAn some one help me out....
TIA. The code is as under.....
if(evt.target ==Button7)
{
System.out.println("Button Pressed");
// String query = "(INSERT INTO LANDMARK VALUES('null', 'null', 'null', 'null'))";

//*********************************Make connection with the database
try {
txtfield.setText(null);
if (conn == null)
{
txtfield.append("Loading JDBC dirver " + "oracle.jdbc.driver.OracleDriver()" + "\n");

//Driver driver=(Driver)Class.forName("oracle.jdbc.driver.OracleDriver()").newInstance();

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("Registering the driver");
//Class.forName("oracle.jdbc.driver.OracleDriver");
txtfield.append("Connecting to the database" +" jdbc racle ci8:webhiqs/donotenter@diglib1$
conn = DriverManager.getConnection ("jdbc racle:thin:@(description=(address=(host= diglib1.cecs.missouri.edu)(protocol=tcp)
(port=1521))(connect_data=(sid=medbio)))", "webhiqs", "donotenter");
//Connection conn=DriverManager.getConnection("jdbc racle ci8:webhiqs/donotenter@diglib1.cecs.missouri.edu:1521:medbio");
//Connection conn=DriverManager.getConnection("jdbc racle:thin:@diglib1.cecs.missouri.edu:$
txtfield.append("Connected" + "\n");

System.out.println("Registering the driver");
} // if ends..................................
System.out.println("CONNECTED TO THE DATABASE");
// String query = ("INSERT INTO LANDMARK" + " VALUES('null', 'null', 'null', 'null'))";

Statement stmt = conn.createStatement();
txtfield.append("Executing query " + query + "\n");
ResultSet rset=stmt.executeQuery(query);

while (rset.next())
txtfield.append(rset.getString(1) + "\n");


// if(state3.executeUpdate(query)>0)
// {
System.out.println("the followed row is inserted");
// }
// else
// {
// System.out.println("out of the if loop");
// }
// state3.close();
}catch (NoClassDefFoundError etc) {etc.printStackTrace();
} catch (SQLException se) {se.printStackTrace();
} catch (Exception e) {e.printStackTrace();} // try-catch ends......................
System.out.println("Out of try block");
txtfield.append("Out of try block ");
}//end of submit button ..................
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
If you put your code between "[ code]" and "[ /code]" without the spaces, it will be easier for us to read and understand.
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
I agree please use code /code in future posts.
More info requested
1. operating system are you using
2. what is ther version of the JDK
3. what is ther version of the JDBC
4. are you gocing to use OCI or thin client
I post code about 6 to 9 months ago please search for it...
I have been busy ... i will try to check back in a few day if you have any questions.

------------------
Multi-Platform Database Developer ( on E.S.T. )


Multi Platform Database Developer & DBA on E.S.T.
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
Working Code Example:
<code>
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {

String url = "jdbcracle:thin:@machinename:1521:sid";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";

Statement stmt;

try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}

catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnectionurl, "USERID", "PASSWD");
stmt = con.createStatement();stmt.executeUpdate(createString);

stmt.close();
con.close();

} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
</code>
hope this helps...
------------------
Multi-Platform Database Developer ( on E.S.T. )
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Access to the Oracle database using Java Applets