| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 564 人关注过本帖
标题:[求助]
只看楼主 加入收藏
任我飞
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-12-20
收藏
 问题点数:0 回复次数:2 
[求助]

向表里追加数据怎样写脚本,各位高手指点1-2,

搜索更多相关主题的帖子: 表里 脚本 数据 
2005-12-20 20:10
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
一个小建议,把“我”字去了,任飞,天高任鸟飞....多雅致

任我飞.....俗了

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2005-12-20 20:13
新坏男人
Rank: 1
等 级:新手上路
威 望:1
帖 子:38
专家分:0
注 册:2005-12-7
收藏
得分:0 

例子::
数据库表
//表:products 列名 数据类型 长度 suppliers 列名 数据类型 长度
// pid int 4 sid int 4
// pname varchar 200 sname varchar 100
// pprice float 8 sregion char 50
// pcolor char 10 sdescription varchar 250


// 表: products_suppliers 列名 数据类型 长度
// pid int 4
// sid int 4
// Quantity int 4

import java.util.*;

import java.sql.*;

class DBAccessor

{
Connection conn;

PreparedStatement ipStmt,rpStmt;

//构造器

DBAccessor() throw SQLException,ClassNotFoundException

{
String dbURL = "jdbc:odbc:Sample";

//装入JdbcOdbc驱动程序

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//建立与数据库的连接

conn = DriverManager.getConnection(dbURL,"sa","123");

//建立插入数据的预处理语句

ipStmt = conn.prepareStatement("INSERT INTO suppliers(sid,sname,sregion,sdescriptin) VALUES(?,?,?,?)");

//建立检索数据的预处理语句

rpStmt = conn.prepareStatement("SELECT * FROM suppliers WHERE sregion = ?");
}

//插入数据的方法

void insertDATA() throw SQLException

{
int sids[] = {200,201,202,203,204},i = 0;

String snames[] = {"Tom", "Jerry", "Dilbert", "Calvin", "Hobbes"};

String sregions[] = {"London", "Mumbai", "New York", "London", "London"};

String sdes[] = {"Pen dealer", "Paper dealer", "Clock dealer", "Pencil dealer"," Pen Paper dealer"}

for(i = 0;i <5;i++)

{
ipStmt.setInt(1,sids[i]);

ipStmt.setString(2,sids[i]);

ipStmt.seString(3,sids[i]);

ipStmt.seString(4,sids[i]);

ipStmt.execute();
}

ipStmt.close();
}

//检索数据的方法

void retrieveData() throw SQLException

{
SesyltSet rs;

rpStmt.setString(1,"London");

rs = rpStmt.executeQuery();

System.out.println("Suppliers table ...\n");

while (rs.next())
{
System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getString(3) + " " + rs.getString(4));
}

rs.close();

rpStmt.close();
}

};

//主类

class DBPSTester

{
public static void main(Striing[] args)

{
try{
DBAccessor dba = new DBAccessor();
dba.insertData();

}
catch(SQLException e)
{
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}

}
}

也许会有点帮助!!

[此贴子已经被作者于2005-12-20 21:23:17编辑过]


/UploadFile/2005-11/2005112317153975.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./UploadFile/2005-11/2005112317153975.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-12-20 21:19
快速回复:[求助]
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014685 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved