Linux 技巧:让进程在后台可靠运行的几种方法

发布网友 发布时间:2022-04-21 02:43

我来回答

5个回答

热心网友 时间:2023-11-04 18:40

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;
}

热心网友 时间:2023-11-04 18:41

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.

热心网友 时间:2023-11-04 18:41

把Category c = new Category();写到循环里面去就好了!
while (rs.next()) {
Category c = new Category();

c.setcId(rs.getInt("cId"));
System.out.println("ci Dao===="+rs.getInt("cId"));
c.setName(rs.getString("name"));
c.setDescribes(rs.getString("describes"));
c.setContentTime(rs.getString("contentTime"));
categoryList.add(c);
}

热心网友 时间:2023-11-04 18:42

Category c = new Category();

这一句放到while循环里面去
否则只创建了一个对象
所有的操作都是对这一个对象进行的
所以只有最后一次循环生效了

必须在每次循环的时候new一个对象才可以

热心网友 时间:2023-11-04 18:42

怎么看只有一个对象 把这个 Category c = new Category();放到while里面吧

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com