package test;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.sql.*;
//import com.borland.dx.sql.dataset.Database;
//import com.borland.dx.sql.dataset.*;
//import test.conn.db;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Applet1 extends Applet {
//
// db conn=null;
//
boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JTextArea jTextArea1 = new JTextArea();
public String JDriver="sun.jdbc.odbc.JdbcOdbcDriver";
public String conURL="jdbc:odbc:test";
public Connection con;
public Statement s;
public String query;
public ResultSet rs;
// Database database1 = new Database();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setLayout(null);
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(66, 30, 224, 22));
jButton1.setBounds(new Rectangle(82, 67, 56, 24));
jButton1.setText("jButton1");
jButton1.addActionListener(new Applet1_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(156, 66, 64, 26));
jButton2.setText("jButton2");
jButton2.addActionListener(new Applet1_jButton2_actionAdapter(this));
jTextArea1.setText("jTextArea1");
jTextArea1.setBounds(new Rectangle(63, 117, 276, 170));
// database1.setConnection(new ConnectionDescriptor("jdbc:odbc:test", "",
// "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
this.add(jTextField1);
this.add(jButton1);
this.add(jButton2);
this.add(jTextArea1);
try
{
Class.forName(JDriver);
}
catch(java.lang.ClassNotFoundException e){
System.out.println("ForName:"+e.getMessage());
}
this.opendb();
}
public boolean opendb(){
boolean bz;
bz=true;
try{
con=DriverManager.getConnection(conURL);
s=con.createStatement();
}
catch(SQLException e){
System.out.println("SQLException:"+e.getMessage());
bz=false;
}
return bz;
}
public void addsql(String dbsql){
this.query=dbsql;
}
public boolean updatedb(){
boolean bz;
bz=true;
try{
s.executeUpdate(query);
}
catch(SQLException e){
System.out.println("SQLException:"+e.getMessage());
bz=false;
}
return bz;
}
public boolean querydb(){
boolean bz;
bz=true;
try{
rs=s.executeQuery(query);
}
catch(SQLException e){
System.out.println("SQLException:"+e.getMessage());
bz=false;
}
return bz;
}
public boolean closedb(){
boolean bz;
bz=true;
try{
s.close();
con.close();
}
catch(SQLException e){
System.out.println("SQLException:"+e.getMessage());
bz=false;
}
return bz;
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
public void jButton1_actionPerformed(ActionEvent e) {
this.closedb();
this.opendb();
this.addsql(jTextField1.getText());
this.updatedb();
this.closedb();
}
public void jButton2_actionPerformed(ActionEvent e) {
this.closedb();
this.opendb();
this.addsql(jTextField1.getText());
this.querydb();
try{
jTextArea1.setText("");
while(this.rs.next()){
jTextArea1.append(rs.getString("id")+"\t"+rs.getString("name")+"\t"+rs.getInt("score")+"\n");
}
}
catch(SQLException f){
System.out.println("SQLException:"+f.getMessage());
}
this.closedb();
}
}
class Applet1_jButton2_actionAdapter implements ActionListener {
private Applet1 adaptee;
Applet1_jButton2_actionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Applet1_jButton1_actionAdapter implements ActionListener {
private Applet1 adaptee;
Applet1_jButton1_actionAdapter(Applet1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java对数据库的操作!
共35个文件
class:7个
java:3个
dep2:2个
需积分: 9 15 下载量 86 浏览量
2008-12-12
13:03:10
上传
评论
收藏 73KB RAR 举报
温馨提示
Java对数据库的操作!对于数据库的初学者很好很有帮助的
资源推荐
资源详情
资源评论
收起资源包目录
1588.rar (35个子文件)
Java对数据库的操作!
test
test.ldb 192B
test.jpx.local 2KB
test.jpx.local~ 2KB
bak
test
conn
db.java~3~ 787B
db.java~2~ 581B
db.java~1~ 582B
db.java~4~ 838B
Applet1.java~6~ 5KB
Applet1.java~3~ 3KB
Applet1.java~9~ 5KB
Applet1.java~8~ 5KB
Applet1.java~2~ 2KB
Applet1.java~10~ 5KB
Applet1.java~4~ 4KB
Applet1.java~5~ 5KB
Applet1.java~1~ 1KB
Applet1.java~7~ 5KB
src
test
conn
db.java 963B
Applet1_jButton2_actionAdapter.class 489B
Applet1.class 4KB
applent2.java 81B
Applet1.java 6KB
Applet1_jButton1_actionAdapter.class 489B
app1.html 363B
Applet1.java.bak 6KB
test.jpx 4KB
test.mdb 108KB
classes
Applet1.html 408B
test
conn
db.class 639B
Applet1_jButton2_actionAdapter.class 648B
Applet1.class 5KB
Applet1_jButton1_actionAdapter.class 648B
package cache
test.dep2 2KB
test.conn.dep2 538B
test.rar 33KB
共 35 条
- 1
资源评论
rtghbnm
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功