急急急!在applet中怎样使用数据库???(100分)

W

wwwlgy

Unregistered / Unconfirmed
GUEST, unregistred user!
在applet中怎样使用数据库???
import java.awt.*;
import java.applet.*;
import java.sql.*;

public class Testmdb extends Applet
{
String newstring;
public void init()
{
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("Sorry, No DB Driver");
newstring=e.toString();
} //try
}
public void start()
{
}
public void paint(Graphics g)
{
g.drawString(newstring, 50, 60 );
}
}
为何结果总是说我找不到类
能有一个具体的例子吗?
 
只听说过serverlet能用数据库,applet不能用数据库吧
 
行是行,不过你发布applet的时候应该将java.sql.*包的内容也打到包里。
不过建议最好使用jdbc驱动,不要用jdbc-odbc桥。
 
不明白什么意思?
你想做什么?
 
用JDBC
是纯Java实现的
如Oracle的JDBC(thin接口)
或用数据代理程序
 
wwwlgy:请继续请继续请继续或结束问题
 
是可以用到数据库的。
如下面用到了一个sql server的driver.
Using the driver in an applet
----------------------------------
- Add the file Sprinta2000.jar to the Archive attribute of the applet tag, e.g.:
<APPLET CODE="..." Codebase="..." ARCHIVE="Sprinta2000.jar" WIDTH="100%" HEIGHT="100%">
...
</APPLET>
or extract the jar in the directory of the applet. You need a browser compatible
with JDK 1.2.x or higher. Most browsers support JDK 1.1.x, only. A solution
is to use the Java Plugin. In this case you need to use the OBJECT tag (IE) or the
EMBED tag (NC).
当然,在这里你可以用你得到的任何一个支持你所用的数据库的driver,而不是Sprinta200.jar
 
TO zeusangel:
你的sql server 的驱动程序哪里得到的,能不能给小弟我分享一下
 
我也在找 SQL SERVER 的驱动程序,如果有的话,
能不能给我一个啊
 
到Mircosoft 的网站上去down.我才当了一个。
 
其实这是一个古老的话题了
这里连不上数据库,不是驱动的问题!
applet 对本地资源的访问受权限的限制
也就是说,如果你完成了本地policy的修改和数字签名
你才有访问数据库的可能!
 
可以啊,我用lotus的BeanMachine可以生成读取数据库的Applet啊
远程访问好像不行,列不出数据,但可以列出字段名
 
不会吧?
Applet的限制是访问的IP必须是Web服务器
如果你的Web服务器和数据库服务器是一个IP就没问题了
 
use servlet or asp to access the database, use applet to communicate with selvlet
or asp through java.net.socket package.
or try to use webservice, it is hot now
 
yyanghhong:看过来,我的有没有你说的用Applet 连Asp --->数据库。有没有这个列子。
我可以单独给你300分。
 
其实比较可行的方案是
Applet与Servlet通信
然后通过Servlet操作数据库。
至于Applet与Servlet通信的手段,有很多:Socket、RMI、CORBA、URLConnection(好象有书说是HTTP隧道技术C)
而且基本上我都试过,
我比较喜欢URlConnection方式,相对Socket易于操作,相对RMI、CORBA少了些烦琐的认证或安全策月问题
 
当然可以用数据库,条件如下:
1,保证浏览器的JVM支持你所使用的JDBC,比如JDBC2啦,保险的做法是将SUN的JDBC2包
也打入到APPLET中去。
2,使用type 4的JDBC驱动,比如mm.mysql, oracle thin driver等,同理也要将驱动打
进去。
基本就这样。
不过我即使觉得这种方式很不安全,而且在速度,发布的容易程度等方面都不好。
最好是用applet通过socket与servlet通信,由servlet负责存取数据库,并对结果进行处
理缓存,再发给applet。
 
import java.io.*;
import java.net.*;
public class Reverse {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Usage: java Reverse "
+ "string_to_reverse");
System.exit(1);
}
String stringToReverse = URLEncoder.encode(args[0]);
URL url = new URL("http://java.sun.com/cgi-bin/backwards");
//change this line to your asp or servlet URL
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(
connection.getOutputStream());
out.println("string=" + stringToReverse);
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
 
不要用直接连接到数据库。你可以用applet 发送一个请求到 服务器,在返回结果数据。
在applet 中显示,用applet 不安全,反编译后什么都被看到了。
 
顶部