左移一位相当于乘2,右移一位相当于除2.length属性里面放的是数组的长度。除2不就求出数组的中间索引了。
创新互联公司是一家专业提供商丘企业网站建设,专注与成都网站设计、网站制作、HTML5建站、小程序制作等业务。10年已为商丘众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
package com.cn.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
//import java.awt.List;
public class Query {
public ListUserVo showUser(){
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ListUserVo list=new ArrayListUserVo();
try{
conn=JDBC_Connection.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from users");
while(rs.next()){
UserVo userVo=new UserVo();
userVo.setId(rs.getInt("id"));
userVo.setName(rs.getString("name"));
userVo.setAge(rs.getInt("age"));
userVo.setTel(rs.getString("tel"));
userVo.setAddress(rs.getString("address"));
list.add(userVo);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
JDBC_Connection.free(rs, conn, stmt);
}
return list;
}
public static void main(String[] args) {
Query query=new Query();
ListUserVo list=query.showUser();
if(list!=null){
System.out.print("id\t");
System.out.print("name\t");
System.out.print("age\t");
System.out.print("tel\t");
System.out.print("address\t");
System.out.println();
for(int i=0;ilist.size();i++){
System.out.print(list.get(i).getId()+"\t");
System.out.print(list.get(i).getName()+"\t");
System.out.print(list.get(i).getAge()+"\t");
System.out.print(list.get(i).getTel()+"\t ");
System.out.print(list.get(i).getAddress()+"\t");
System.out.println();
}
}
}
}
要自己加驱动,,,,这个你应该可以看懂吧,,
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
//import java.awt.List;
public class Query {
public ListUserVo showUser(){
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ListUserVo list=new ArrayListUserVo();
try{
conn=JDBC_Connection.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from users");
while(rs.next()){
UserVo userVo=new UserVo();
userVo.setId(rs.getInt("id"));
userVo.setName(rs.getString("name"));
userVo.setAge(rs.getInt("age"));
userVo.setTel(rs.getString("tel"));
userVo.setAddress(rs.getString("address"));
list.add(userVo);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
JDBC_Connection.free(rs, conn, stmt);
}
return list;
}
public static void main(String[] args) {
Query query=new Query();
ListUserVo list=query.showUser();
if(list!=null){
System.out.print("id\t");
System.out.print("name\t");
System.out.print("age\t");
System.out.print("tel\t");
System.out.print("address\t");
System.out.println();
for(int i=0;ilist.size();i++){
System.out.print(list.get(i).getId()+"\t");
System.out.print(list.get(i).getName()+"\t");
System.out.print(list.get(i).getAge()+"\t");
System.out.print(list.get(i).getTel()+"\t ");
System.out.print(list.get(i).getAddress()+"\t");
System.out.println();
}
}
}
}