package Test;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import util.JdbcUtil;
public class TestMain {
/**
* @param args
*/
public static void main(String[] args) {
//JOptionPane.showMessageDialog(null,"a","提示",1);
Connection conn = null;
Statement st = null;
ResultSet rs = null;
PreparedStatement pre = null;
try {
conn = JdbcUtil.getConnection();
//st = conn.createStatement();
/**
* 查
*/
st = conn.createStatement();
rs = st.executeQuery("select * from student");
while(rs.next()){
System.out.println(rs.getString(2));
}
/**
* 查2
*/
// st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE );
// rs = st.executeQuery("select * from student where stuid=27");
// rs.afterLast();
//
// rs.absolute(5);
// while(rs.previous()){
// System.out.println(rs.getString(2));
// }
/***
* 改
*/
// pre = conn.prepareStatement("update student set STUSEX = 'M' where stuid=27");
// pre.executeUpdate("update student set STUSEX = 'F' where stuid=27");
// System.out.println("更改成功!");
/**
* 改2
*/
// st = conn.createStatement();
// st.execute("update student set STUSEX = 'M' where stuid=27");
// System.out.println("更改成功!");
/**
* 增
*/
// String insertSql;
// pre = conn.prepareStatement("insert into student values(?,?,?,?)");
// pre.setString(1, "xtj");
// pre.setString(2, "M");
// pre.setInt(3, 22);
// pre.setDate(4, new Date(new java.util.Date().getTime()));
// pre.executeUpdate();
// System.out.println("增添成功!");
/**
* 增2
*/
// st = conn.createStatement();
// st.executeUpdate("insert into student values('xtj2','M',22,'1989-03-11')");
// System.out.println("增添成功!");
/**
* 删除
*/
// String insertSql;
// pre = conn.prepareStatement("delete from student where stuid=24");
// pre.executeUpdate();
// System.out.println("删除成功!");
/***
* 删除2
*/
// st = conn.createStatement();
// st.executeUpdate("delete from student where stuid=26");
// System.out.println("删除成功!");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JdbcUtil.free(rs, pre, conn);
}
}
}