2022,3,5学习日记


今天重头开始的普通javaweb功能的实现

首先是html界面

请登录









用户名:



密 码:






然后是后台dao层面的建立

public int modifyData(String sql,Object obj[]) {//增删改
int result=0;
Connection conn=ConnMysql.getConn();
try {
PreparedStatement ps=conn.prepareStatement(sql);
for(int i=0;i ps.setObject(i+1, obj[i]);
}
result=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return result;
}



public static ResultSet getDataByAny(String sql,Object obj[]) {//查
Connection conn=ConnMysql.getConn();
ResultSet rs=null;
try {
PreparedStatement ps=conn.prepareStatement(sql);
for(int i=0;i ps.setObject(i+1, obj[i]);
}
rs=ps.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return rs;
}

public static Connection getConn() {
Connection conn=null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/2022.3.4","root","111111");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;

}

出现层面调用的混乱问题,然后是html层和servlet层连接失败。

相关