当前位置: 技术问答>java相关
急啊,版主及高手请进!!!!快啊!!
来源: 互联网 发布时间:2015-06-18
本文导语: 代码如下: 出错的地方我已经用-》标出来了。 import java.sql.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class aApplet extends Applet { TextArea TA=new TextArea(); TextField TF1=new TextField(); TextField TF2=...
代码如下:
出错的地方我已经用-》标出来了。
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class aApplet extends Applet
{
TextArea TA=new TextArea();
TextField TF1=new TextField();
TextField TF2=new TextField();
public void init()
{
add(TA);
add(TF1);
add(TF2);
}
String myurl= "jdbc:odbc:kcsj";
String query = "SELECT * FROM jiaoxue";
-> try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
TF1.setText("drive ok!");
}
catch(Exception e)
{
TF1.setTexet("drive fail!");
e.printStackTrace();
}
try
{
Connection accessCon=DriverManager.getConnection (myurl, "", "");
if(!accessCon.isclose())
TF2.setText("connect ok!");
Statement ST;
ResultSet RS;
ST=accessCon.createStatement();
RS=ST.execueQuery(query);
String AS=RS.getString();
RS.close();
TA.setText(AS);
accessCon.close();
}
catch(SQLException ex)
{
TF2.setText("connect fail!");
ex.printStackTrace();
-> }
}
报错信息如下:
C:My DocumentsworkKCSJnewaApplet.java:20: illegal start of type
try
^
C:My DocumentsworkKCSJnewaApplet.java:48: expected
}
^
2 errors
帮帮忙拉
出错的地方我已经用-》标出来了。
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class aApplet extends Applet
{
TextArea TA=new TextArea();
TextField TF1=new TextField();
TextField TF2=new TextField();
public void init()
{
add(TA);
add(TF1);
add(TF2);
}
String myurl= "jdbc:odbc:kcsj";
String query = "SELECT * FROM jiaoxue";
-> try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
TF1.setText("drive ok!");
}
catch(Exception e)
{
TF1.setTexet("drive fail!");
e.printStackTrace();
}
try
{
Connection accessCon=DriverManager.getConnection (myurl, "", "");
if(!accessCon.isclose())
TF2.setText("connect ok!");
Statement ST;
ResultSet RS;
ST=accessCon.createStatement();
RS=ST.execueQuery(query);
String AS=RS.getString();
RS.close();
TA.setText(AS);
accessCon.close();
}
catch(SQLException ex)
{
TF2.setText("connect fail!");
ex.printStackTrace();
-> }
}
报错信息如下:
C:My DocumentsworkKCSJnewaApplet.java:20: illegal start of type
try
^
C:My DocumentsworkKCSJnewaApplet.java:48: expected
}
^
2 errors
帮帮忙拉
|
你的代码错误很多!!主要是笔误!!!!
告诉你解决方案,我修改后的代码,不过其它的错误你自己解决吧
主要是你的try{}catch{}必须在init()里面!!!
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class aApplet extends Applet
{
TextArea TA=new TextArea();
TextField TF1=new TextField();
TextField TF2=new TextField();
public void init()
{
add(TA);
add(TF1);
add(TF2);
String myurl= "jdbc:odbc:kcsj";
String query = "SELECT * FROM jiaoxue";
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
TF1.setText("drive ok!");
}
catch(Exception e)
{
TF1.setTexet("drive fail!");
e.printStackTrace();
}
try
{
Connection accessCon=DriverManager.getConnection (myurl, "", "");
if(!accessCon.isclose())
TF2.setText("connect ok!");
Statement ST;
ResultSet RS;
ST=accessCon.createStatement();
RS=ST.execueQuery(query);
String AS=RS.getString();
RS.close();
TA.setText(AS);
accessCon.close();
}
catch(SQLException ex)
{
TF2.setText("connect fail!");
ex.printStackTrace();
}
}
}
告诉你解决方案,我修改后的代码,不过其它的错误你自己解决吧
主要是你的try{}catch{}必须在init()里面!!!
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class aApplet extends Applet
{
TextArea TA=new TextArea();
TextField TF1=new TextField();
TextField TF2=new TextField();
public void init()
{
add(TA);
add(TF1);
add(TF2);
String myurl= "jdbc:odbc:kcsj";
String query = "SELECT * FROM jiaoxue";
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
TF1.setText("drive ok!");
}
catch(Exception e)
{
TF1.setTexet("drive fail!");
e.printStackTrace();
}
try
{
Connection accessCon=DriverManager.getConnection (myurl, "", "");
if(!accessCon.isclose())
TF2.setText("connect ok!");
Statement ST;
ResultSet RS;
ST=accessCon.createStatement();
RS=ST.execueQuery(query);
String AS=RS.getString();
RS.close();
TA.setText(AS);
accessCon.close();
}
catch(SQLException ex)
{
TF2.setText("connect fail!");
ex.printStackTrace();
}
}
}
|
you can not connec to database from applet directly, it's restricted by the secret permission
try to use a servlet. Or change your applet to a frame
try to use a servlet. Or change your applet to a frame