怎么在Java中往数据库表插入新的内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么在Java中往数据库表插入新的内容相关的知识,希望对你有一定的参考价值。
(1)传统方式持久化数据库对象 —— 表 如:Hibernate等;
//保存一个数据库对象
public boolean saveEntity(Object entity)
try
getHibernateTemplate().save(entity);
return true;
catch (Exception e)
e.printStackTrace();
return false;
(2) 直接SQL语句插入
如:insert into ...... 参考技术A 执行sql语句啊,你要用JDBC或者一些框架连接到数据库,在执行插入sl语句
insert into(表名) values(1,1,1,1,1,1);
values(是要插入的数据类型要跟数据库表中设计的类型一致)不然报错。
在一个数组中插入数据?怎么插?
将一个正数插到从小到大排列的正数序列中Var
A:array[1..10000] of word;
i,n:integer;
Procedure insert(var n:integer;x:word);
Var I,j:integer;
Begin
If x>a[n] then a[n+1]:=x
Else if x<=a[1] then begin
For I:=n downto 1 do a[i+1]:=a[i];
A[1]:=x;
End
Else begin
For I:=1 to n-1 do if (x>a[i])and(x<=a[i+1] ) then begin j:=I; break; end;
For I:=n downto j+1 do a[i+1]:=a[i];
A[j+1]:=x;
End;
Inc(n);
End;
begin
n:=1;
a[1]:=3;
insert(n,4);
insert(n,1);
insert(n,2);
for i:=58 downto 1 do insert(n,i);
for i:=1 to n do write(a[i]:3);
end. 参考技术A Private Sub CreateData(n() As Integer)
Dim i As Integer
Dim j As Integer
Dim temp As Integer
Print "ÔʼÊý¾ÝΪ£º"
Randomize
For i = 1 To 20
n(i) = Int(Rnd * 90) + 10
Print n(i);
If i Mod 10 = 0 Then Print
Next i
Print "´ÓСµ½´óÅÅÐò£º"
For i = 1 To 19
For j = i + 1 To 20
If n(i) > n(j) Then temp = n(i): n(i) = n(j): n(j) = temp
Next j
Print n(i);
If i Mod 10 = 0 Then Print
Next i
Print n(i)
End Sub
Private Sub Form_Click()
Dim m(1 To 21) As Integer
Dim position As Integer
Dim i As Integer
Dim nflag As Integer
Dim x As Integer
CreateData m()
x = Val(InputBox("ÇëÊäÈëÒª²åÈëµÄÕûÊý"))
Print "Òª²åÈëµÄÕûÊýΪ£º"; x
position = 1
For i = 1 To 20
If m(i) > x Then
position = i
nflag = 1
Exit For
End If
Next i
If nflag = 1 Then
For i = 20 To position Step -1
m(i + 1) = m(i)
Next i
m(position) = x
Else
m(21) = x
End If
Print "²åÈëxºóµÄÊý×éΪ:"
For i = 1 To 21
Print m(i);
If i Mod 10 = 0 Then Print
Next i
End Sub本回答被提问者和网友采纳 参考技术B js中使用push() ;你知道你想知道什么语言的
以上是关于怎么在Java中往数据库表插入新的内容的主要内容,如果未能解决你的问题,请参考以下文章