import java.sql.*;
import java.util.Vector;
public class Test {
public static void main(String[] args) {
String strQuery = "SELECT * FROM rkd";
int[] id = getID(strQuery);
//è¾åºæµè¯idæ°ç»
for(int e : id){
System.out.println(e);
}
}
/**
* æ ¹æ®æ¥è¯¢ä¸²è·å¾ç¼å·æ°ç»
* @param strQuery æ¥è¯¢ä¸²
* @return ç¼å·æ°ç»
*/
public static int[] getID(String strQuery) {
int[] id = null;
try {
//æ¥è¯¢æ°æ®åºä¸çä¼åid
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Exam01","sa","123456");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(strQuery);
//å°ææidåå
¥ä¸´æ¶åévectä¸
Vector<Integer> vect = new Vector<Integer>();
while(rs.next()){
vect.add(rs.getInt(1));
}
//å°ææid转åå°æ°ç»ä¸
id = new int[vect.size()];
for(int i=0; i<id.length; i++){
id[i] = Integer.parseInt(vect.get(i).toString());
}
}
catch (Exception e) {
e.printStackTrace();
}
return id;
}
}
å¨Combo1çä¸æäºä»¶ä¸å å
¥ä»£ç ï¼å¦ä¸ï¼
Private Sub combo1_DropDown()
Me.combo1.Clear
Dim CN As New ADODB.Connection
CN.Open"Provider=microsoft.jet.oledb.4.0;data source=" & App.Path &"\æ°æ®åºå称.mdb"
DimJ As Integer
DimST As String
Dimrso As ADODB.Recordset
Setrso = New ADODB.Recordset
ST= "select * from 表å"
rso.Open ST, CN, adOpenKeyset, adLockOptimistic
IfNot rso.EOF Then
rso.MoveFirst
End If
ForJ = 1 To rso.RecordCount
Me.combo1.AddItem rso("å段å")
rso.MoveNext
NextJ
rso.Close
Set CN = Nothing
End sub
温馨提示:答案为网友推荐,仅供参考