applet连接SQL SERVER失败
各位大虾,我写了一个APPLET来连接本机的SQL SERVER2000,代码如下:
编译可以通过,但用APPLETVIEWER看时,总提示:Caused by: java.io.FileNotFoundException: D:\Inetpub\wwwroot\Sun\jdbc\odbc\JdbcO
dbcDriver.class (系统找不到指定的路径。),不知道是和原因,
我的环境变量配置为:
JAVA_HOME="D:\JDK1.4.2";
PATH=%JAVA_HOME%\BIN;
CLASSPATH=".;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib
import java.awt.*;
import java.applet.*;
import java .sql.*;
public class Applet1 extends Applet
{
TextArea theVisits=new TextArea (30,120);
//显示数据库的内容
TextField theStatus=new TextField ("",80);
//显示打开数据库的信息。相当于程序的状态栏
Connection theConnection; //数据库的连接方法
Statement theStatement; //代表一个发送到数据库来执行的数据库命令
ResultSet theResult; //读取的数据结果,也就是数据库返回的结果
ResultSetMetaData theMetaData;
//包含了有关数据库命令执行后 返回结果的有用信息。
String theDataSource; //包含了被访问数据库或者数据源的名称,用URL形式表示 .
String theUser; //数据库的用户名
String thePassword; //数据库的密码
public void init()
{
add(theVisits);
add(theStatus);
theVisits.setEditable (false); //设置文本区域不可以被用户写入
theStatus.setEditable (false); //设置文本区域不可以被用户写入
openConnection(); //打开数据库的连接
execSQLCommand("select * from score"); //从数据库中读取内容
closeConnection(); //关闭已经打开的数据库
}
public void openConnection()
{
theDataSource="jdbc:odbc:rocket1";
theUser="rocket";
thePassword="rocket";
try
{
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
theConnection=DriverManager.getConnection(theDataSource,theUser,thePassword);
theStatus.setText("Status:OK");
}
catch (Exception e)
{
handleException(e);
}
}
public void execSQLCommand(String command)
{
try{
theStatement=theConnection.createStatement();
theResult=theStatement.executeQuery (command);
theMetaData=theResult.getMetaData ();
int columnCount=theMetaData.getColumnCount ();
theVisits.setText("");
while(theResult.next ())
{
for(int i =1;i<=columnCount;i++)
{
String colValue=theResult.getString(i);
if(colValue==null)colValue="";
theVisits.append (colValue+";");
}
theVisits.append ("\n");
}
}catch(Exception e)
{
handleException(e);
}
}
public void closeConnection()
{
try{
theConnection.close ();
}
catch(Exception e)
{
handleException(e);
}
}
public void handleException(Exception e)
{
theStatus.setText("Error1:"+e.getMessage ());
e.printStackTrace ();
if(e instanceof SQLException)
{
while((e=((SQLException)e).getNextException ())!=null)
{
System.out.println(e);
}
}
}
}