package com.hfkj.group1;import java.io.PrintStream;
import java.sql.*;public class DataBase
{ public static Connection con;
public Statement stmt; public DataBase()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:MZY", "", "");
stmt = con.createStatement(1004, 1007);
}
catch(ClassNotFoundException classnotfoundexception)
{
System.out.println(classnotfoundexception.getMessage());
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception.getMessage());
}
catch(Exception exception)
{
System.out.println(exception.toString());
}
} public ResultSet queryExe(String s)
{
ResultSet resultset = null;
try
{
resultset = stmt.executeQuery(s);
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception.getMessage());
}
return resultset;
} protected void finalize()
{
try
{
con.close();
con = null;
stmt = null;
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception.getMessage());
}
}
}package com.hfkj.group1;import java.io.PrintStream;
import java.sql.*;
public class StudentInfo
{ private String xuHao;
private String name;
private String address;
private String sex;
private int age;
private DataBase db;
private ProcessCharacter pc; public StudentInfo()
{
db = new DataBase();
pc = new ProcessCharacter();
} public void setXuHao(String s)
{
xuHao = s;
} public String getXuHao()
{
return xuHao;
} public void setName(String s)
{
name = pc.getStr(s);
} public String getName()
{
return name;
} public void setAddress(String s)
{
address = pc.getStr(s);
} public String getAddress()
{
return address;
} public void setSex(String s)
{
sex = pc.getStr(s);
} public String getSex()
{
return sex;
} public void setAge(int i)
{
age = i;
} public int getAge()
{
return age;
} public ResultSet query(String s)
{
return db.queryExe(s);
} public boolean delete(String s)
{
int i = db.stmt.executeUpdate("delete from StudentInfo where XuHao='" + s + "'");
if(i == 1)
{
return true;
}
return false;
SQLException sqlexception;
sqlexception;
System.out.println(sqlexception.toString());
return false;
} public boolean update()
{
String s = "update StudentInfo set Name='" + name + "', Age=" + age + ", Sex='" + sex + "', Address='" + address + "'" + " where XuHao='" + xuHao + "'";
int i = db.stmt.executeUpdate(s);
if(i == 1)
{
return true;
}
return false;
SQLException sqlexception;
sqlexception;
System.out.println(sqlexception.getMessage());
return false;
} public boolean insert()
{
String s = "Insert into StudentInfo values('" + xuHao + "','" + name + "'," + age + ",'" + sex + "','" + address + "')";
int i = db.stmt.executeUpdate(s);
if(i == 1)
{
return true;
}
return false;
SQLException sqlexception;
sqlexception;
System.out.println(sqlexception.getMessage());
return false;
} public static void main(String[] ar)
{
ResultSet rs=null;
StudentInfo st=new StudntInfo();
rs=st.query("select G.*, G.Chinese+G.Math+G.English as ZongFen from GradeInfo");
try
{
while(rs.next())
System.out.println(rs.getString(6));
}
catch(SQLException se)
{
System.out.println(se.getMessage());
}
}
}
import java.sql.*;public class DataBase
{ public static Connection con;
public Statement stmt; public DataBase()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:MZY", "", "");
stmt = con.createStatement(1004, 1007);
}
catch(ClassNotFoundException classnotfoundexception)
{
System.out.println(classnotfoundexception.getMessage());
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception.getMessage());
}
catch(Exception exception)
{
System.out.println(exception.toString());
}
} public ResultSet queryExe(String s)
{
ResultSet resultset = null;
try
{
resultset = stmt.executeQuery(s);
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception.getMessage());
}
return resultset;
} protected void finalize()
{
try
{
con.close();
con = null;
stmt = null;
}
catch(SQLException sqlexception)
{
System.out.println(sqlexception.getMessage());
}
}
}package com.hfkj.group1;import java.io.PrintStream;
import java.sql.*;
public class StudentInfo
{ private String xuHao;
private String name;
private String address;
private String sex;
private int age;
private DataBase db;
private ProcessCharacter pc; public StudentInfo()
{
db = new DataBase();
pc = new ProcessCharacter();
} public void setXuHao(String s)
{
xuHao = s;
} public String getXuHao()
{
return xuHao;
} public void setName(String s)
{
name = pc.getStr(s);
} public String getName()
{
return name;
} public void setAddress(String s)
{
address = pc.getStr(s);
} public String getAddress()
{
return address;
} public void setSex(String s)
{
sex = pc.getStr(s);
} public String getSex()
{
return sex;
} public void setAge(int i)
{
age = i;
} public int getAge()
{
return age;
} public ResultSet query(String s)
{
return db.queryExe(s);
} public boolean delete(String s)
{
int i = db.stmt.executeUpdate("delete from StudentInfo where XuHao='" + s + "'");
if(i == 1)
{
return true;
}
return false;
SQLException sqlexception;
sqlexception;
System.out.println(sqlexception.toString());
return false;
} public boolean update()
{
String s = "update StudentInfo set Name='" + name + "', Age=" + age + ", Sex='" + sex + "', Address='" + address + "'" + " where XuHao='" + xuHao + "'";
int i = db.stmt.executeUpdate(s);
if(i == 1)
{
return true;
}
return false;
SQLException sqlexception;
sqlexception;
System.out.println(sqlexception.getMessage());
return false;
} public boolean insert()
{
String s = "Insert into StudentInfo values('" + xuHao + "','" + name + "'," + age + ",'" + sex + "','" + address + "')";
int i = db.stmt.executeUpdate(s);
if(i == 1)
{
return true;
}
return false;
SQLException sqlexception;
sqlexception;
System.out.println(sqlexception.getMessage());
return false;
} public static void main(String[] ar)
{
ResultSet rs=null;
StudentInfo st=new StudntInfo();
rs=st.query("select G.*, G.Chinese+G.Math+G.English as ZongFen from GradeInfo");
try
{
while(rs.next())
System.out.println(rs.getString(6));
}
catch(SQLException se)
{
System.out.println(se.getMessage());
}
}
}
解决方案 »
- 我这里有两个JAVABEAN的程序但无法编译请高人帮助
- jsp页面如何获取url参数
- 关于JAVA 的各位前辈来帮忙 谢谢啦
- jspsmartupload上传下载的目录必须是绝对目录么
- session问题请教
- Mybatis 3 整合 Spring mvc 3, spring 3 的问题?解决立即结贴给分!
- 急急急~~~~~请高手指点该如何调用,怎样将JSP和VBA结合起来,或者是在后台怎样实现调用Excel进程来完成操作。
- 线程的返回值?
- 为什么我不能把文件插入到数据库中?
- list<map>去重问题 求解决 请看详情
- 求救:网页中屏蔽掉退格键(Back Space)问题!
- 我想在当天发布的新闻后面显'new',该怎么写代码?
<center>
<div align="center" top=50 left=300 width=328 style="width: 70; height: 11">
<center>
<table border="1" width="328" height="218">
<tr>
<td width="328" height="31" colspan="3" align="center">
<p align="center"><font color="#0000FF"><b>综合信息查询</b></font></td>
</tr>
<tr>
<td width="27" height="29" align="center"><input type="checkbox" name="yw" onClick="disableRadio(this)"></td>
<td width="81" height="29" align="left"><font color="#0000FF" size="2">语文成绩</font></td>
<td width="197" height="29"><font color="#0000FF" size="2">
<input type=radio name="ch" value="1" checked>升序 <input type=radio name="ch" value="0">降序</font></td>
</tr>
<tr>
<td width="27" height="29" align="center"><input type="checkbox" name="sx" onClick="disableRadio(this)"></td>
<td width="81" height="29" align="left"><font color="#0000FF" size="2">数学成绩</font></td>
<td width="197" height="29"><font color="#0000FF" size="2">
<input type=radio name="ma" value="1" checked>升序 <input type=radio name="ma" value="0">降序</font></td>
</tr>
<tr>
<td width="27" height="30" align="center"><input type="checkbox" name="yy" onClick="disableRadio(this)"></td>
<td width="81" height="30" align="left"><font color="#0000FF" size="2">英语成绩</font></td>
<td width="197" height="30"><font color="#0000FF" size="2">
<input type=radio name="en" value="1" checked>升序 <input type=radio name="en" value="0">降序</font></td>
</tr>
<tr>
<td width="27" height="30" align="center"><input type="checkbox" name="zf" onClick="disableRadio(this)"></td>
<td width="81" height="30" align="left"><font color="#0000FF" size="2">总成绩</font></td>
<td width="197" height="30"><font color="#0000FF" size="2">
<input type=radio name="tl" value="1" checked>升序 <input type=radio name="tl" value="0">降序</font></td> </tr>
<tr>
<td width="27" height="30" align="center"><input type="checkbox" name="kh" onClick="disableRadio(this)"></td>
<td width="81" height="30" align="left"><font color="#0000FF" size="2">考号</font></td>
<td width="197" height="30"><font color="#0000FF" size="2">
<input type=radio name="exId" value="1" checked>升序 <input type=radio name="exId" value="0">降序</font></td>
</tr>
<tr>
<td width="328" height="36" colspan="3" align="center">
<p align="center"><input type="submit" value=" 查询 "></p>
</td>
</tr>
</table>
</form>
</center>
</div>
</center>
<%
String yw=request.getParameter("yw");
String sx=request.getParameter("sx");
String yy=request.getParameter("yy");
String zf=request.getParameter("zf");
String kh=request.getParameter("kh");
String strSql="",chValue="",maValue="",enValue="",tlValue="",exIdValue="";
if(yw==null && sx==null && yy==null && zf==null && kh==null)
return ;
else
{
if(yw!=null){
chValue=request.getParameter("ch");
if(chValue.equals("0")){
strSql="T.Chinese desc,";
}
else{
strSql="T.Chinese,";
}
}
if(sx!=null){
maValue=request.getParameter("ma");
if(maValue.equals("0")){
strSql+="T.Math desc,";
}
else{
strSql+="T.Math,";
}
}
if(yy!=null){
enValue=request.getParameter("en");
if(enValue.equals("0")){
strSql+="T.English desc,";
}
else{
strSql+="T.English,";
}
}
if(zf!=null){
tlValue=request.getParameter("tl");
if(tlValue.equals("0")){
strSql="T.ZongFen desc,";
}
else{
strSql="T.ZongFen,";
}
}
if(kh!=null){
exIdValue=request.getParameter("exId");
if(exIdValue.equals("0")){
strSql="T.ExamId desc";
}
else{
strSql="T.ExamId";
}
}
}
if(strSql.endsWith(","))
strSql=strSql.substring(0,strSql.length()-1);
ResultSet rs=st.query("select T.* from (select G.*,G.Chinese+G.Math+G.English as ZongFen,S.Name,S.Age,S.Sex,S.Address from GradeInfo G,StudentInfo S where "+
" G.XuHao=S.XuHao) T order by "+strSql);
%>
testmysql.jsp如下: --------------------------------------------------
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//testDB为你的数据库名
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>