JSP中如何取得MSSQL資料庫表中自動增長的ID主鍵值

時間 2021-08-11 15:55:34

1樓:匿名使用者

這個可以這樣子從資料表裡找出當前記錄的userid值:

select userid from studentwhere

userid=(select max(userid) from student)

之後再用jsp中語句,如:

dbconnection dbc=new dbconnection();

//dbconnection為資料庫連線類resultset rs=dbc.executequery();

rs.next();

int userid=rs.getint("userid");

//這裡的userid即為當前插入記錄的userid值了.

rs.close();

dbc.close();

2樓:甫濡姬冰心

如:建一個表student有屬性列userid,username其中userid為int型別只讀自動加1的主鍵(也就是每插入一條記錄都會自動加1),那麼如何在jsp中得到當前插入行的userid值(比如:我向表裡插入了三條記錄,在我插入第三條記錄時userid的值應為3,那麼如何得到這個3)?

先建立儲存過程:

create

procedure

addrec

(@outid

intoutput,

@name

varchar(25))as

declare

@idint

insert

into

nametable(name)

values(@name)

select

@id=@@identity

select

@outid=@id

go然後這樣用:

callablestatement

stmt=con.preparecall("");

stmt.registeroutparameter(1,types.integer,1);

stmt.setstring(2,"name.");

stmt.execute();

intid=stmt.getint(1);

stmt.close()

如何將從資料庫中取得的資料顯示在lable上

定義乙個函式利用儲存過程從資料庫中讀出資料.當然也可以不用儲存過程 public static system.data.datarow chaxun1 string name,string type 呼叫函式,將值賦給要顯示它的控制項 this.label6.text chaxun1 combobo...

如何從資料庫表中取值然後賦值到jsp頁面的某個文字框中

寶寶and雨軒 你需要把值先傳到 jsp頁面上 string username request.getparameter username 得到值以後直接取值 username 求助 如何實現將從資料庫中查詢出來的值顯示在jsp頁面的文字框中。 愛吃魚油 在c控制層action,定義乙個屬性stri...

如何將jsp中js裡的變數傳到另jsp中

乙個頁面像另乙個頁面提交變數最常見的有兩種情況 1 get方式中,將變數附加到url中,例如http zhidao.baidu.這個鏈結中變數entry和ishq的值就傳遞給了頁面267751952.html。2 post方式的話可以在表單中提交,設定乙個隱藏域,用js把變數值賦值給隱藏域,提交的時...