public class ConnDB {
private Connection ct = null;
//驱动程序名
String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名scutcs
String url = "jdbc:mysql://127.0.0.1:3306/develop";
// MySQL配置时的用户名
String user = "root";
// Java连接MySQL配置时的密码
String password = "wzy123"; public static Connection getConn(){
try{
Class.forName(driver);
ct = DriverManager.getConnection(url, user, password);
}
catch(Exception e){
e.printStackTrace();
}
return ct;
} public int add(String day,String time,
String volname,String volclass,String voltel,String volemail){
Connection con = DbConnect.this.getConn();
int num = -; try {
java.sql.Statement statement = con.createStatement();
num = statement.executeUpdate( "insert into tb_volinfo(day,time,volname,volclass,voltel,volemail) "
+ "values('"+day+"','"+time+"','"+volname+"','"+volclass+"','"+voltel+"','"+volemail+"')"); if(statement!=null){
statement.close();
}
if(con!=null){
con.close();//关闭数据库连接
}
} catch (Exception e) {
e.printStackTrace();
} return num;
}
public boolean SelectVal(String volname,String voltel){
Connection con1 = DbConnect.this.getConn();
ResultSet result =null; try {
java.sql.Statement statement = con1.createStatement();
result = statement.executeQuery("select * from tb_volinfo where volname='"+volname+"' and voltel='"+voltel+"';");
while(result.next()){
return true;
}
if(statement!=null){
statement.close();
}
if(con1!=null){
con1.close();//关闭数据库连接
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

最新文章

  1. 慕课网-Java入门第一季-7-4 编程练习
  2. SSO(单点登录)
  3. Invalid Image Path - No image found at the path referenced under key "CFBundleIconFile": Icon.png
  4. js获取时间戳
  5. Saltstack系列5:Saltstack之pillar组件
  6. 纯CSS3代码实现简单的图片轮播
  7. Embedding Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office
  8. android百度定位
  9. Java排序之排序大综合
  10. 比较JqGrid与XtraGrid
  11. bis.org
  12. 洛谷P4051 [JSOI2007]字符加密 后缀数组
  13. .NET Core和.NET Standard
  14. Zookeeper原理架构
  15. 97. Interleaving String (String; DP)
  16. mongodb常用基本命令(根据工作需要,不断更新)
  17. java 一般类属性设置常量 用以长久使用
  18. Luogu 1429 平面最近点对 | 平面分治
  19. Linux命令-用户管理命令:useradd,passwd,who,w
  20. 遍历Map集合四中方法

热门文章

  1. [转载]MySQL concat函数的使用
  2. Python编码规范 -- Python Style Guide
  3. Django Rest Framework(一)
  4. OpenGL帧缓存对象(FBO:Frame Buffer Object)
  5. 【转载】linux获取mac地址
  6. Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程
  7. Hearbeat 工作原理
  8. 主攻ASP.NET.4.5.1 MVC5.0之重生:Web项目语音朗读网页文本,简单语音提示浏览状态
  9. iOS清除缓存功能开发
  10. linux内核调试+qemu+eclipse【转】