这是java代码:
package mybean;
import *;
import java.sql.*;
public class A{
String id="";
String name="";
String fenshu="";
public A()
{
id="";
name="";
fenshu="";
}
public void setId(String id)
{
this.id=id;
}
public String getId()
{
return id;
}
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setFenshu(String fenshu)
{
this.fenshu=fenshu;
}
public String getFenshu()
{
return fenshu;
}
public void conn()
{
if(id!="")
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn1 = DriverManager.getConnection("jdbc:odbc:student");
Statement stat1 = conn1.createStatement();
String sql1 = "select * from chengji where id='"+id+"'";
ResultSet rs1 = stat1.executeQuery(sql1);
while(rs1.next())
{
id=rs1.getString(1);
name=rs1.getString(2);
fenshu=rs1.getString(3);
}
if(rs1.next()==false)
{
id="";name="";fenshu="";
}
else
{
}
stat1.close();
conn1.close();
}
catch(Exception e)
{
System.out.print("请规范操作!");
}
}
else
{
}
}
public static void main(String[] args)
{
A a=new A();
a.setId("002");
a.conn();
if(a.name!="")
{
System.out.println(" id:"+a.id);
System.out.println(" name:"+a.name);
System.out.println("fenshu:"+a.fenshu);
}
else
{
System.out.println("数据库里没有这个id!");
}
}
}