processing-MySQL learning2-append()

来源:互联网 发布:世界旅游组织数据库 编辑:程序博客网 时间:2024/05/16 11:02
import de.bezier.data.sql.*;MySQL mysql;User[] userArray=new User[0];void setup(){  size(100,100);    String database="mydatas";  String user="hui1570";  String pass="04263028";    mysql=new MySQL(this,"localhost",database,user,pass);    if(mysql.connect())  {    String p1="us%";    //remember:we should add ' to %s when we are querying    String sqlString="SELECT * FROM user where username like '%s' and id < %d order by id limit %d";    mysql.query(sqlString,p1,10,3);  }  while(mysql.next())  {    User add=new User(mysql.getInt(1),mysql.getString(2),mysql.getString(3));    //append(new) is used to add a new entry to the list.    userArray=(User[])append(userArray,add);    //Wrong: cannot convert from Object to User[]: userArray=append(userArray,add);    //Wrong: cannot invoke append(User) on the array User[]: userArray=userArray.append(add);  }    for(int i=0;i<userArray.length;i++)  {    println(userArray[i].id+"  "+userArray[i].username+"  "+userArray[i].password);  }  }//create a classclass User{  int id;  String username;  String password;  User(int i,String u,String p)  {    id=i;    username=u;    password=p;  }}

0 0
原创粉丝点击