计算机毕业设计主要代码:
主要代码
MyDAO.java类是程序的核心代码,在该类里面实现了所有和数据库相关的操作。
package family.yin.senqi.dao;
import java.sql.*;
import family.yin.senqi.model.*;
public class MyDAO{
private Connection con = null;
private Statement st = null;
/**
* 构造函数,初始化con(类中定义的私有变量)
*/
//实例化的时候完成和数据库的连接
public MyDAO() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myFamaly","sa","758688");
}
catch (SQLException ex1) {
ex1.printStackTrace();
} }
//判断用户名和密码是否正确
public boolean isLogin(ModelUser user) throws SQLException
{
boolean flag=false;
System.out.println("user.username:"+user.getUsername());
System.out.println("user.password:"+user.getPassword());
String sql="select * from tbuser where username='"+user.getUsername()+"' and password='"+user.getPassword()+"'";
System.out.println(sql);
st=con.createStatement();
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
System.out.println("登录成功");
flag=true;
}return flag; }
//查询数据库
public ModelOne[] getMyTableResults(int tables,String indexid) throws Exception {
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = st.executeQuery("select * from mytable where indexid = '"+indexid+"' and tables="+tables);
rs.last();
int row = rs.getRow();
ModelOne[] ms = new ModelOne[row];
rs.beforeFirst();
int i = 0;
〖资料来源:计算机毕业论文 www.xiaoniu168.com〗
第17页为计算机毕业论文主要代码2......