用java连接数据库的小程序 楼主把邮箱给我javaGUI通信录,满足你的要求可以发给你 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主留下邮箱,发给你,呵呵很简单的,如果用jbuilder之类的话,要不了半个小时就能做一个满足要求的,就是几条语句,楼主留下邮箱,发给你,不过建议楼主自己写一个简单的,其实用到的东西不多,首先可以锻炼自己,增加自己的动手能力,最主要是可以增加自己的自信心,因为你自己解决了这个问题,这是最重要的, 楼主是为了学java吗?还是为了应付考试呀? 你是要B/S架构的还是C/S架构的 import java.sql.*;import java.util.ArrayList;import java.util.List;import dto.Student;public class StudentDAO implements IStudentDAO{ public static void main(String[] args) {// Student s=new Student("aa",12,13.4f);// StudentDAO dao=new StudentDAO();// dao.intsertStudent(s);// StudentDAO dao=new StudentDAO();// List<Student>list=dao.getAllStudent();// dao.print(list);// StudentDAO dao=new StudentDAO();// dao.updateStudent(); StudentDAO dao=new StudentDAO(); dao.deleteStudent(); } public void print(List<Student> list) { for(Student s:list) System.out.println(s.getName()+","+s.getAge()+","+s.getHeight()); } public Connection getConnection() { Connection con=null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/lwy","sa","lwy"); } catch (Exception e) { e.printStackTrace(); } return con; } public boolean deleteStudent() { boolean flag=false; Connection con=null; PreparedStatement pstmt=null; String sql="delete from student where id=14"; try { con=this.getConnection(); pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); int count=pstmt.executeUpdate(); if(count>0) flag=true; else flag=false; } catch (Exception e) { e.printStackTrace(); flag=false; } finally { try { if(pstmt!=null) pstmt.close(); if(con!=null) con.close(); } catch (Exception e) { // TODO: handle exception } } return flag; } public boolean updateStudent() { boolean flag=false; Connection con=null; PreparedStatement pstmt=null; String sql="update student set age=12 where id=13"; try { con=this.getConnection(); pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); int count=pstmt.executeUpdate(); if(count>0) flag=true; else flag=false; } catch (Exception e) { e.printStackTrace(); flag=false; } finally { try { if(pstmt!=null) pstmt.close(); if(con!=null) con.close(); } catch (Exception e) { // TODO: handle exception } } return flag; } @Override public boolean intsertStudent(Student s) { Connection con=null; PreparedStatement pstmt=null; String sql="Insert into Student (name,age,height) values(?,?,?)"; boolean flag=false; try { con=this.getConnection(); pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); pstmt.setString(1, s.getName()); pstmt.setInt(2, s.getAge()); pstmt.setFloat(3, s.getHeight()); int count=pstmt.executeUpdate(); if(count>0) flag=true; else flag=false; } catch (Exception e) { e.printStackTrace(); flag=false; } finally { try { if(pstmt!=null) pstmt.close(); if(con!=null) con.close(); } catch (Exception e) { // TODO: handle exception } } return flag; } @Override public List<Student> getAllStudent() { Connection con=null; PreparedStatement pstmt=null; ResultSet rs=null; String sql="select * from student"; List<Student> list=new ArrayList<Student>(); try { con=this.getConnection(); pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs=pstmt.executeQuery(); while(rs.next()) { Student s=new Student(rs.getString("name"),rs.getInt("age"),rs.getFloat("height")); list.add(s); } } catch (Exception e) { e.printStackTrace(); } finally { try { if(rs!=null); rs.close(); if(pstmt!=null) pstmt.close(); if(con!=null) con.close(); } catch (Exception e) { // TODO: handle exception } } return list; }}简单的增删改查全实现了。你自己加个窗体就ok了。 楼主只是要一个ConnectionManager? 晕 这还用上来问么? 书上没有么? 百度搜一下“JAVA学生信息管理系统”,很多人借鉴的程序。网上很多流传 pinyin float 型 1.58045517E9 转换成 1580455200 oracle分页 Tomcat6动态装载问题(很急) J2EE实现文件下载的问题,请求高手帮忙 关于httpclient读取网站flash的问题 关于 struts2 中 action 和 前台 jsp 传值 介绍一款基于字典的中文分词器ShuzhenAnalyzer JMS到底是用做干什么得???? 奇怪的问题? JAVA高手、大侠请进来帮忙解决!小弟非常感谢! 求助:MySql可视化管理工具
很简单的,如果用jbuilder之类的话,要不了半个小时就能做一个满足要求的,就是几条语句,
楼主留下邮箱,发给你,不过建议楼主自己写一个简单的,其实用到的东西不多,首先可以锻炼自己,增加自己的动手能力,
最主要是可以增加自己的自信心,因为你自己解决了这个问题,这是最重要的,
import java.util.ArrayList;
import java.util.List;import dto.Student;public class StudentDAO implements IStudentDAO{
public static void main(String[] args) {
// Student s=new Student("aa",12,13.4f);
// StudentDAO dao=new StudentDAO();
// dao.intsertStudent(s);
// StudentDAO dao=new StudentDAO();
// List<Student>list=dao.getAllStudent();
// dao.print(list);
// StudentDAO dao=new StudentDAO();
// dao.updateStudent();
StudentDAO dao=new StudentDAO();
dao.deleteStudent();
}
public void print(List<Student> list)
{
for(Student s:list)
System.out.println(s.getName()+","+s.getAge()+","+s.getHeight());
}
public Connection getConnection()
{
Connection con=null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/lwy","sa","lwy");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public boolean deleteStudent()
{
boolean flag=false;
Connection con=null;
PreparedStatement pstmt=null;
String sql="delete from student where id=14";
try {
con=this.getConnection();
pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
int count=pstmt.executeUpdate();
if(count>0)
flag=true;
else
flag=false;
} catch (Exception e) {
e.printStackTrace();
flag=false;
}
finally
{
try {
if(pstmt!=null)
pstmt.close();
if(con!=null)
con.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return flag;
}
public boolean updateStudent()
{
boolean flag=false;
Connection con=null;
PreparedStatement pstmt=null;
String sql="update student set age=12 where id=13";
try {
con=this.getConnection();
pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
int count=pstmt.executeUpdate();
if(count>0)
flag=true;
else
flag=false;
} catch (Exception e) {
e.printStackTrace();
flag=false;
}
finally
{
try {
if(pstmt!=null)
pstmt.close();
if(con!=null)
con.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return flag;
} @Override
public boolean intsertStudent(Student s) {
Connection con=null;
PreparedStatement pstmt=null;
String sql="Insert into Student (name,age,height) values(?,?,?)";
boolean flag=false;
try {
con=this.getConnection();
pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
pstmt.setString(1, s.getName());
pstmt.setInt(2, s.getAge());
pstmt.setFloat(3, s.getHeight());
int count=pstmt.executeUpdate();
if(count>0)
flag=true;
else
flag=false;
} catch (Exception e) {
e.printStackTrace();
flag=false;
}
finally
{
try {
if(pstmt!=null)
pstmt.close();
if(con!=null)
con.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return flag;
}
@Override
public List<Student> getAllStudent() {
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
String sql="select * from student";
List<Student> list=new ArrayList<Student>();
try {
con=this.getConnection();
pstmt=con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs=pstmt.executeQuery();
while(rs.next())
{
Student s=new Student(rs.getString("name"),rs.getInt("age"),rs.getFloat("height"));
list.add(s);
}
} catch (Exception e) {
e.printStackTrace();
}
finally
{
try {
if(rs!=null);
rs.close();
if(pstmt!=null)
pstmt.close();
if(con!=null)
con.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return list;
}}
简单的增删改查全实现了。你自己加个窗体就ok了。