aspose file tools*
The moose likes Java in General and the fly likes Applet and JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Applet and JDBC" Watch "Applet and JDBC" New topic
Author

Applet and JDBC

Atonu Bhowmik
Greenhorn

Joined: Nov 07, 2000
Posts: 9
Hello friends,
I want your help to solve the given below problem :
Friends, I want to query data from table using applet & jdbc. I have create a button and on pressing the button the query should execute.
The code is complied with no error but is not executing.
Please help me out.
Atonu Bhowmik

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class japp extends Applet implements ActionListener
{
public String no="";
public String na="";
public String sl="";
public int x=0;
public Statement st;
public ResultSet rs;
public Connection cn;
public String msg = "";
public void init()
{
Button bt = new Button("Query");
add(bt);

bt.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{


String str = ae.getActionCommand();
if(str.equals("Query"))


{
try
{
st = cn.createStatement();
rs = st.executeQuery("select empno,ename,sal from emp where empno = 7934");

while(rs.next())
{
no = rs.getString("empno");
na = rs.getString("ename");
sl = rs.getString("sal");
//x++;
}
}
catch(SQLException e)
{
msg = e.getMessage();
}
}
repaint();
}

public void paint(Graphics g)
{
g.drawString(msg,60,60);
g.drawString(no,60,70);
g.drawString(na,120,70);
g.drawString(sl,200,70);

}
public static void main(String arg[])
{
japp jp = new japp();
jp.init();

try
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e)
{
System.out.println("Class not found");
}
Connection cn = DriverManager.getConnection("jdbc dbc:ab_oracle","scott","tiger");
System.out.println("Connection established");
}

catch(SQLException e)
{
System.out.println("SQL Exception : "+e.getMessage());
}

}
}
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi,
Are you getting an exception ?
Are you using a Type 4 driver i.e. All Java driver ? If not, then you cannot directly connect to the Database using any other driver.
If so, is it in the codebase for the applet ?
Is the Applet host and the database host the same (with the same IP address) ?
If not, this would never work as an applet can only connect back to the same machine from which it was loaded.
Try and print out some statements in your code to see where it is failing.
Hope this helps.
Ashwin.
Atonu Bhowmik
Greenhorn

Joined: Nov 07, 2000
Posts: 9
Hello Ashwin,
Thanks for the tips, but I think Type-1 driver is the driver that can connect to any database and I have used this one.
Actually I want a user interface ie. applet and in backend the oracle database connected through jdbc-odbc bridge.
The user interface would have Add,delete,query etc button and on pressing buttons specific work has to be done.
My problem is where should I write the jdbc code ( in init(), start() or shall I create a instance of jdbc code in applet).
I am comfortable with applet and jdbc, but I struck when I integrate this two.
Please help me out,since I am new in Java.
waiting for your valuable assistance.
with regards,
Atonu Bhowmik
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi,
You need an all Java driver if you are connecting directly from the Applet to the DB (without a server in between).
If you have a server that gets the applets requests and makes JDBC calls on its behalf and returns results, then any type of driver is OK.
Ashwin.
Atonu Bhowmik
Greenhorn

Joined: Nov 07, 2000
Posts: 9
Hello Ashwin,
Thanks for your valauable tips. Its really help me out.
I want to make one more request,How the different oracle user connect to the database.
How do I dynamically make the JDBC connection for each user from Applet.
Please suggest.

regards,
Atonu
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi,
To do that, you need to create a new Connection object passing the username, passwd, DBString as the parameters. You can do that at login time.
Ashwin.
Atonu Bhowmik
Greenhorn

Joined: Nov 07, 2000
Posts: 9
Hello Ashwin,
Thanks for everything.
Dear Ashwin, it will be very helpfull for me if you forward your e-mail ID so that in future ,I can take guideness from you.
My e-mail Id is smd@bom4.vsnl.net.in
Hope you will do it for me.
Thanks.
Atonu
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
If he does that then the REST of us won't benefit from his guidance. If you have questions, please post them in an open forum, not e-mail.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi Atonu,
Please post any questions on the forum. It is beneficial as you get different perspectives of looking at your problem and possibly different answers. Also, it benefits all of us (as Cindy has rightly pointed out). In fact, thats what the discussion board is for !!
Ashwin.
Atonu Bhowmik
Greenhorn

Joined: Nov 07, 2000
Posts: 9
Hi Ashwin,
I think u r right and I appreciate your suggestion.
Thanks
Atonu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet and JDBC
 
Similar Threads
Oracle Connectivity with thin drivers !!
need help in executeUpdate() please
oracle Conenctivity using Thin Drivers
Classes12.zip Thin Drivers
Oracle Connectivity with thin drivers