当前位置: 技术问答>java相关
delphi里往一个表里添加数据很简单,哪位大侠会用jbuilder7来添加数据啊?
来源: 互联网 发布时间:2017-04-12
本文导语: 在delphi里:通过点击按钮 adotable1.open; adotable1.insert; adotable1.fieldbyname('用户名').asstring:=xxx; adotable1.post; 在jbuilder里怎么实现呢? 比如我往表里新加入一条记录,这条记录‘用户名’字段的值是qqq.怎么能实现呢, 高手...
在delphi里:通过点击按钮
adotable1.open;
adotable1.insert;
adotable1.fieldbyname('用户名').asstring:=xxx;
adotable1.post;
在jbuilder里怎么实现呢?
比如我往表里新加入一条记录,这条记录‘用户名’字段的值是qqq.怎么能实现呢,
高手帮忙啊,做个例子发到我的邮箱也行,pjwanglong2000@sohu.com
adotable1.open;
adotable1.insert;
adotable1.fieldbyname('用户名').asstring:=xxx;
adotable1.post;
在jbuilder里怎么实现呢?
比如我往表里新加入一条记录,这条记录‘用户名’字段的值是qqq.怎么能实现呢,
高手帮忙啊,做个例子发到我的邮箱也行,pjwanglong2000@sohu.com
|
Insert data into a table on a database
import java.sql.*;
import java.util.*;
import java.util.Date;
/*@Linda:08.08.2001*/
public class DBInsert {
private Connection con;
private DatabaseMetaData dbMeta;
private String driver =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
public DBInsert() {
createConnection();
executeSQL();
}
private void createConnection() {
Properties props = new Properties();
props.put("user", "sa");
props.put("password", "plato17");
try {
Class.forName(driver);
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver:"
+ "//linda-a7agpelgn:1051;databasename=sunrise", props);
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
printDate();
printDBInfo();
printLevel();
}
/* Timestamp */
private void printDate() {
Date date = new Date();
Timestamp time = new Timestamp(date.getTime());
System.out.println("Timestamp: " + time);
}
private void executeSQL() {
String[] insert = { "Joseph", "Weinstein", "clj.databases", "B.E.A" };
try {
String sql =
"INSERT INTO NGMembers VALUES(?,?,?,?,?)";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, 19);
for (int i = 0; i
import java.sql.*;
import java.util.*;
import java.util.Date;
/*@Linda:08.08.2001*/
public class DBInsert {
private Connection con;
private DatabaseMetaData dbMeta;
private String driver =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
public DBInsert() {
createConnection();
executeSQL();
}
private void createConnection() {
Properties props = new Properties();
props.put("user", "sa");
props.put("password", "plato17");
try {
Class.forName(driver);
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver:"
+ "//linda-a7agpelgn:1051;databasename=sunrise", props);
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
printDate();
printDBInfo();
printLevel();
}
/* Timestamp */
private void printDate() {
Date date = new Date();
Timestamp time = new Timestamp(date.getTime());
System.out.println("Timestamp: " + time);
}
private void executeSQL() {
String[] insert = { "Joseph", "Weinstein", "clj.databases", "B.E.A" };
try {
String sql =
"INSERT INTO NGMembers VALUES(?,?,?,?,?)";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, 19);
for (int i = 0; i