java人员信息管理代码 java人员管理系统( 三 )


return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('" + stuNo + "','" + name +"','" + gender + "'," + age + ")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入数据库遇到异常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo =" + stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != nullrs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
数据库你自己弄吧,我没时间弄了!初学得多动手哦
求一段简单的JAVA代码 要求员工工资管理系统的一个增删改查代码 , 谢谢了对数据库进行增删改查?
以下是 sql server 2013+java.实现的是对MSC对象的增删改查.
需要下载连接驱动程序:com.microsoft.sqlserver.jdbc.SQLServerDriver
网上搜一下就行
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
class MSC
{
public String MscID;
public String MscName;
public String MscCompany;
public float MscLongitude;
public float MscLatitude;
public float MscAltitude;
public MSC(String MscID, String MscName, String MscCompany,
float MscLongitude, float MscLatitude,float MscAltitude){
this.MscID = MscID;
this.MscName = MscName;
this.MscCompany = MscCompany;
this.MscLongitude =MscLongitude;
this.MscLatitude = MscLatitude;
this.MscAltitude = MscAltitude;
}
}
public class sqlserverjdbc {
public Connection getConnection(){
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=gsm"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "123"; //密码
Connection dbConn = null;
【java人员信息管理代码 java人员管理系统】try {
Class.forName(driverName);
dbConn =DriverManager.getConnection(dbURL, userName, userPwd);
} catch (Exception e) {
e.printStackTrace();
}
return dbConn;
}
public void printUserInfo(){
Connection con = getConnection();
Statement sta = null;
ResultSet rs = null;
System.out.println("打印表格MSC信息");
try {
sta = con.createStatement();
rs = sta.executeQuery("select * from MSC信息");
System.out.println("MscID\tMscName\tMscCompany\tMscLongitude\tMscLatitude\tMscAltitude");
while(rs.next()){
System.out.println(rs.getString("MscID")+"\t"+
rs.getString("MscName")+"\t"+
rs.getString("MscCompany")+"\t"+
rs.getFloat("MscLongitude")+"\t"+
rs.getFloat("MscLatitude")+"\t"+
rs.getFloat("MscAltitude"));
}
con.close();
sta.close();

推荐阅读