资源简介
JDBC入门汇总及范例讲解 ,具体过程与效果看博文
http://blog.csdn.net/evankaka/article/details/45370609

代码片段和文件信息
package com.mucfc;
import java.sql.*;
public class JdbcTest {
//定义数据库驱动程序
private static final String DBDRIVER=“com.mysql.jdbc.Driver“;
//数据库连接地址
private static final String DBURL=“jdbc:mysql://localhost:3306/school“;//school表示数据库
//数据库用户名
private static final String DBUSER=“root“;
//电脑上的数据库密码
private static final String DBPASS=“christmas258@“;
public void testDDL(){
try {
//1.注册驱动
Class.forName(DBDRIVER);
//2.获取连接
Connection conn = DriverManager.getConnection(DBURLDBUSERDBPASS);
//3.创建Statement对象
Statement stmt = conn.createStatement();
//4.准备sql语句
String sql =“CREATE TABLE student(sid INT PRIMARY KEYsname VARCHAR(20)age INT)“;
//5.通过statement对象发送sql语句返回执行结果
int count = stmt.executeUpdate(sql);
System.out.println(“CREATE TABLE student......“);
//6.打印执行结果
System.out.println(“影响了“+count+“条记录“);
//执行插入操作
System.out.println(“Inserting records into the table...“);
sql = “INSERT INTO student “ +
“VALUES (100 ‘小文‘ 18)“;
stmt.executeUpdate(sql);
sql = “INSERT INTO student “ +
“VALUES (101 ‘大林‘ 25)“;
stmt.executeUpdate(sql);
sql = “INSERT INTO student “ +
“VALUES (102 ‘阿白‘ 30)“;
stmt.executeUpdate(sql);
sql = “INSERT INTO student “ +
“VALUES(103 ‘小小‘ 28)“;
stmt.executeUpdate(sql);
System.out.println(“Inserted records into the table...“);
//执行查找操作
sql = “SELECT* FROM student“;
System.out.println(“SELECT records FROM the table...“);
ResultSet rs = stmt.executeQuery(sql);
//输出查找结果
while(rs.next()){
//先获取数据
int sid = rs.getInt(“sid“);
String sname = rs.getString(“sname“);
int age = rs.getInt(“age“);
//打印结果
System.out.print(“sid: “ + sid);
System.out.print(“ sname: “ +sname);
System.out.println(“ age: “ + age);
}
rs.close();
//7.关闭资源
try {
if(stmt!=null)
{
stmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if(conn!=null)
{
conn.close();
}
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
/* JdbcTest jdbcTest=new JdbcTest();
jdbcTest.CreateTableTest();
jdbcTest.InsertTest();
jdbcTest.SelectTest();*/
SqlDB sqlDB=new SqlDB();
sqlDB.CreatTable();
sqlDB.InsertData(309 “小红“12);
sqlDB.InsertData(33 “小灰“34);
sqlDB.InsertData(23 “阿大“145);
sqlDB.SelectDataWithId(33);
}
public void CreateTableTest(){
//获取连接
Conne
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-04-29 19:58 JDBCLearning1\
文件 413 2015-04-29 19:59 JDBCLearning1\.classpath
文件 389 2015-04-29 19:58 JDBCLearning1\.project
目录 0 2015-04-29 19:58 JDBCLearning1\.settings\
文件 598 2015-04-29 19:58 JDBCLearning1\.settings\org.eclipse.jdt.core.prefs
目录 0 2015-05-06 08:59 JDBCLearning1\bin\
目录 0 2015-05-06 08:59 JDBCLearning1\bin\com\
目录 0 2015-05-06 08:59 JDBCLearning1\bin\com\mucfc\
文件 4946 2015-05-06 08:59 JDBCLearning1\bin\com\mucfc\JdbcTest.class
文件 3996 2015-05-06 08:59 JDBCLearning1\bin\com\mucfc\SqlDB.class
目录 0 2015-04-29 19:59 JDBCLearning1\src\
目录 0 2015-04-29 19:59 JDBCLearning1\src\com\
目录 0 2015-04-29 20:31 JDBCLearning1\src\com\mucfc\
文件 6261 2015-04-30 08:20 JDBCLearning1\src\com\mucfc\JdbcTest.java
文件 4247 2015-04-30 08:33 JDBCLearning1\src\com\mucfc\SqlDB.java
相关资源
- jdbcTemplate分页彻底解决,使用游标滚
- TeraJDBC__indep_indep.16.20.00.06.zip
- 基于yml 配置方式 ,实现springBoot+sha
- JDBC连接实现简单学生管理系统附数据
- JDBC API 参考教程第三版(2003).rar
- Jdbc经典案例之图书管理系统
- 达梦数据库JDBC驱动包
- 标准struts2和mvc写的用户管理
- 数据库与excel导入导出(JDBCmyeclipse)
- 教学楼管理信息系统
- servlet+jdbc实现微信公众号开发
- 简单图书的增删改查
- teradata jdbc最新和老驱动打包
- PI 数据库JDBC管理员指南 2010版
- webservice+jdbc
- 达梦数据库驱动dmjdbcdrive每个jdk版本对
- JDBC东软电信报表系统
- instantclient-jdbc-windows.x64-18.3.0.0.0dbru.
- 查询系统JDBC+struts2
- Warehouse_management.zip
- spring内置jdbctemplate使用demo
- logstash-input-jdbc-4.2.3离线安装包
- struts2(包括增删改查的实现,及登录
- 一本糊涂账-基于Swing和JDBC开发的图形
- ojdbc6-11.2.0.1.0
- 尚硅谷]_宋红康_4天贯通JDBC
- 工单管理系统源码
- Spring mvc + Spring + Spring jdbc 整合 demo
- 使用 Spring MVC + JDBC Template 实现登录
- SpringMVC+Spring+SpringJDBC整合框架
评论
共有 条评论