半点优化网 http://www.bdxc.net/
当前位置首页 > 网站技术问题> 正文

我在List里面放入对象,可是取每个对象的Id属性得到的都是一样的值,怎么回事??以下是部分代码,请高手帮忙

2021-06-01 11:29:50 暂无评论 22 网站技术问题 对象   放入   属性

rs = ps.executeQuery(sql);你这括号里怎么还有sql呢,把他去掉.给你个参考的代码public List<StudentsInfo> findAll() throws Exception { List<StudentsInfo> studentList=new ArrayList<StudentsInfo>(); // 涓庢暟鎹簱寤虹珛杩炴帴 conn=UtilDatabase.getConnection(); // sql锻戒护 String sql="select * from stu_stuInfo"; stmt=conn.prepareStatement(sql); // 镓цstmt骞惰繑锲沥st缁撴灉板? ResultSet rst=stmt.executeQuery(); // 阆嶅巻srt缁撴灉板? while(rst.next()){ // 鎶婇亶铡嗗缑鍒扮殑鍊煎~鍏呭埌瀹炰綋绫讳腑 student=new StudentsInfo(); student.setId(rst.getInt("id")); student.setStuAddress(rst.getString("stuAddress")); student.setStuAge(rst.getInt("stuAge")); student.setStuName(rst.getString("stuName")); student.setStuNum(rst.getInt("stuNum")); student.setStuPwd(rst.getString("stuPwd")); student.setStuSex(rst.getString("stuSex")); studentList.add(student); } UtilDatabase.close(conn); return studentList; }

time_t t = 0;char day[20] = {0};t = time(0);//获取系统时间,此时t存放的是系统时间的秒值(从1970年1月1日0时开始到当前时间)strftime (day, sizeof(day), "%Y-%m-%d %H:%M:%S", gmtime (&t)); //转换为字符串格式,这里的例子是 年-月-日 时:分:秒这里给出的是Linux下的例子,需要包含头文件#include <sys/time.h>。如果是在windows下,你可以自己找找相应的头文件即可下面是MSDN里关于时间函数的示例,仔细看几遍,相信你以后对时间操作的问题就不会抓瞎了#include <time.h>#include <stdio.h>#include <sys/types.h>#include <sys/timeb.h>#include <string.h>void main(){ char tmpbuf[128], ampm[] = "AM"; time_t ltime; struct _timeb tstruct; struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 }; /* Set time zone from TZ environment variable. If TZ is not set, * the operating system is queried to obtain the default value * for the variable. */ _tzset(); /* Display operating system-style date and time. */ _strtime( tmpbuf ); printf( "OS time:\t\t\t\t%s\n", tmpbuf ); _strdate( tmpbuf ); printf( "OS date:\t\t\t\t%s\n", tmpbuf ); /* Get UNIX-style time and display as number and string. */ time( <ime ); printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime ); printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) ); /* Display UTC. */ gmt = gmtime( <ime ); printf( "Coordinated universal time:\t\t%s", asctime( gmt ) ); /* Convert to time structure and adjust for PM if necessary. */ today = localtime( <ime ); if( today->tm_hour > 12 ) { strcpy( ampm, "PM" ); today->tm_hour -= 12; } if( today->tm_hour == 0 ) /* Adjust if midnight hour. */ today->tm_hour = 12; /* Note how pointer addition is used to skip the first 11 * characters and printf is used to trim off terminating * characters. */ printf( "12-hour time:\t\t\t\t%.8s %s\n", asctime( today ) + 11, ampm ); /* Print additional time information. */ _ftime( &tstruct ); printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm ); printf( "Zone difference in seconds from UTC:\t%u\n", tstruct.timezone ); printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); printf( "Daylight savings:\t\t\t%s\n", tstruct.dstflag ? "YES" : "NO" ); /* Make time for noon on Christmas, 1993. */ if( mktime( &xmas ) != (time_t)-1 ) printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) ); /* Use time structure to build a customized time string. */ today = localtime( <ime ); /* Use strftime to build a customized time string. */ strftime( tmpbuf, 128, "Today is %A, day %d of %B in the year %Y.\n", today ); printf( tmpbuf );}程序运行结果OS time: 21:51:03OS date: 05/03/94Time in seconds since UTC 1/1/70: 768027063UNIX time and date: Tue May 03 21:51:03 1994Coordinated universal time: Wed May 04 04:51:03 199412-hour time: 09:51:03 PMPlus milliseconds: 279Zone difference in seconds from UTC: 480Time zone name: Daylight savings: YESChristmas Sat Dec 25 12:00:00 1993Today is Tuesday, day 03 of May in the year 1994.

猜你喜欢