原生JDBC的使用
2024-10-09 11:31:52
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;
}
}
最新文章
- 慕课网-Java入门第一季-7-4 编程练习
- SSO(单点登录)
- Invalid Image Path - No image found at the path referenced under key ";CFBundleIconFile";: Icon.png
- js获取时间戳
- Saltstack系列5:Saltstack之pillar组件
- 纯CSS3代码实现简单的图片轮播
- Embedding Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office
- android百度定位
- Java排序之排序大综合
- 比较JqGrid与XtraGrid
- bis.org
- 洛谷P4051 [JSOI2007]字符加密 后缀数组
- .NET Core和.NET Standard
- Zookeeper原理架构
- 97. Interleaving String (String; DP)
- mongodb常用基本命令(根据工作需要,不断更新)
- java 一般类属性设置常量 用以长久使用
- Luogu 1429 平面最近点对 | 平面分治
- Linux命令-用户管理命令:useradd,passwd,who,w
- 遍历Map集合四中方法
热门文章
- [转载]MySQL concat函数的使用
- Python编码规范 -- Python Style Guide
- Django Rest Framework(一)
- OpenGL帧缓存对象(FBO:Frame Buffer Object)
- 【转载】linux获取mac地址
- Laravel 调试利器 —— Laravel Debugbar 扩展包安装及使用教程
- Hearbeat 工作原理
- 主攻ASP.NET.4.5.1 MVC5.0之重生:Web项目语音朗读网页文本,简单语音提示浏览状态
- iOS清除缓存功能开发
- linux内核调试+qemu+eclipse【转】