Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-07
2
Medium Priority
?
528 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
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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

564 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