?
Solved

JDBC and JApplet ( how to include jar files and ..)

Posted on 2003-03-07
2
Medium Priority
?
522 Views
Last Modified: 2013-11-23
HI:
 How do i connect an applet to jdbc thin driver? My connection works in application but not applet because i need to make to include the libraries needed by oracle in my jar file? How do i do that?

my applet code :import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
//import jdbc.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;  



public class pro extends JApplet implements ActionListener {
JLabel badgel;

JTextField badget;
JTextField badgea;
JButton ok, clear;

Container pane;
JPanel panel ,pan;
public pro(){

 }

public void init(){

//ActionEventHandler handler =new ActionEventHandler();
 
panel=new JPanel(new FlowLayout());
pane=getContentPane();

badgel=new JLabel("Badge");
panel.add(badgel);


badget=new JTextField(" ",5);

badget.addActionListener(this);
badgea=new JTextField(5);

pan=new JPanel(new GridLayout(2,1));
badgea.setEditable(false);
pan.add(badgel);
pan.add(badget);
pan.add(badgea);

ok=new JButton("OK");
ok.addActionListener(this);
clear=new JButton("Clear");
clear.addActionListener(this);
panel.add(clear);
panel.add(ok);
pane.add(panel,BorderLayout.NORTH);
pane.add(pan,BorderLayout.SOUTH);
String sourceURL;
String user;
String password;
String server;
String port;
Connection con;
String sid;
String source;
try{


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


sourceURL=getParameter("url");
 source="jdbc:oracle:thin:@klm:1521:KLMPMIS ";

server=getParameter("server");
port=getParameter("port");
password=getParameter("password");
 user=getParameter("user");
sid=getParameter("sid");

if(sourceURL.equals(source)&&server.equals("klm")&&port.equals("1521")&&password.equals("combtest")&&user.equals("combtest")&&sid.equals("KLMPMIS"))
{ Class.forName("oracle.jdbc.driver.OracleDriver");


con=DriverManager.getConnection(sourceURL,user,password);
Statement statement=con.createStatement();
String sq="INSERT INTO TEST"+"(NAME)"+"VALUES(+'"badget.setText()"')";
statement.executeUpdate(sq);




}
JOptionPane.showMessageDialog(null,"Connection established");

con.close();

}
catch(ClassNotFoundException cnfe){

JOptionPane.showMessageDialog(null,cnfe);
}
catch(SQLException sqle){
JOptionPane.showMessageDialog(null,sqle);
}









}


}
 //class ActionEventHandler implements ActionListener{

 public void actionPerformed(ActionEvent event){

if(event.getSource()==ok)

{

badgea.setText(badget.getText());

}//if

if(event.getSource()==clear){

badget.setText(" ");
badgea.setText(" ");

}//if

}//action




}  

my html file

<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET codebase="oracle.jar"
     code     = "pro.class"
     width     = "500"
     height     = "300"
     >
</APPLET>
<Param  name="url" values="jdbc:oracle:thin:@klm:1521:KLMPMIS ">
<Param name="port" values="1521">
<Param name="server" values="KLM">
<Param name="user" values="combtest">
<Param name="password" values="combtest>

</CENTER>
</BODY>
</HTML>
Could any one send a sample of a code that works with html ?Is there any applet code that access jdbc in a more proper way ? Pls help since i am beginner?


Thank you




















































 

0
Comment
Question by:Jasbir21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
RayGun earned 280 total points
ID: 8093735
When using an applet u need to put the jar files into your <path to java plug-in>/lib/ext folder... That way the java plug-in will find the classes.

(usually something like c:\program\javasoft\jre\1.4\lib\ext if you're on a windows system).

Also you should be aware of the restrictions that apply when using an applet with JDBC, take a look at this page to get the information you need:
http://www.sybase.com/detail/1,6904,1000696,00.html

Good luck
0
 

Author Comment

by:Jasbir21
ID: 8229329
Thanks for the help.Sorry for posting the accepted answer late.
God bless you

Jasbir
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question