随笔分类 -  JDBC

摘要:public interface UserDao { public void addUser(User user); public User getUser(int userId); public User findUser(String loginName, String password); public void update(User user)... 阅读全文
posted @ 2013-12-10 11:30 剑握在手 阅读(600) 评论(0) 推荐(0) 编辑
摘要:使用该工具类需要从spring开发包中导入spring.jar和commons-logging.jar,这个模板是线程安全的。 JdbcTemplate: public class JdbcTemplateTest { static JdbcTemplate jdbc = new JdbcTemplate(JdbcUtils.getDataSource()); /**... 阅读全文
posted @ 2013-12-09 20:43 剑握在手 阅读(591) 评论(0) 推荐(0) 编辑
摘要:使用DBCP必须用的三个包: commons-dbcp-1.2.1.jar, commons-pool-1.2.jar, commons-collections-3.1.jar。 配置参数。 Java API: BasicDataSourceFactory.createDataSource(properties); package cn.itcast.jdbc; ... 阅读全文
posted @ 2013-12-09 00:04 剑握在手 阅读(424) 评论(0) 推荐(0) 编辑
摘要:DBCP是Apache开发的数据源API,使用的话需要导入dbcp jar包、collections jar包、pool jar包。 其数据源匹配的配置文件格式如下: #连接设置 driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/jdbc username=root passw... 阅读全文
posted @ 2013-12-08 22:34 剑握在手 阅读(1327) 评论(0) 推荐(0) 编辑
摘要:连接池代码: public class MyDataSource2{ private static String url = "jdbc:mysql://localhost:3306/jdbc"; private static String user = "root"; private static String password = ""; p... 阅读全文
posted @ 2013-12-08 18:46 剑握在手 阅读(291) 评论(0) 推荐(0) 编辑
摘要:public class OtherApi { /** * @param args * @throws SQLException * @throws InterruptedException */ public static void main(String[] args) throws SQLExce... 阅读全文
posted @ 2013-12-07 10:57 剑握在手 阅读(352) 评论(0) 推荐(0) 编辑
摘要:public class ScrollTest { /** * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { scroll(); } ... 阅读全文
posted @ 2013-12-07 00:10 剑握在手 阅读(231) 评论(0) 推荐(0) 编辑
摘要:public class BatchTest { /** * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { long start = System... 阅读全文
posted @ 2013-12-06 23:44 剑握在手 阅读(235) 评论(0) 推荐(0) 编辑
摘要:package test;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;/* 简陋工具类 */public final class JdbcUtils { private static String url="jdbc:mysql://localhost:3306/world"; private static String user = " 阅读全文
posted @ 2013-12-06 15:51 剑握在手 阅读(421) 评论(0) 推荐(0) 编辑
摘要:曾经有过一个两层构架的时代,前台就是界面,后台就是存储过程,存储过程把业务逻辑和数据操作一手包办了。 用存储过程写东西比较复杂,大部分Java程序员或许都对此不太了解,因为我们如今的三层架构使用高级语言来充当中间的业务逻辑层。但是这种东西关键时候还是很有用的,下面是一个简单例子: DELIMITER $$ #分隔符重新定义 DROP PROCEDURE IF EXISTS `worl... 阅读全文
posted @ 2013-12-06 15:47 剑握在手 阅读(270) 评论(0) 推荐(0) 编辑
摘要:public class SavePointTest { /** * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { test(); } static void test() throws SQLException { Connection conn = null; Statement st = null; ResultSet rs = null; Savepoint sp ... 阅读全文
posted @ 2013-12-06 12:56 剑握在手 阅读(374) 评论(0) 推荐(0) 编辑
摘要:public class TxTest { public static void main(String[] args) throws SQLException { test(); } static void test() throws SQLException { Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = JdbcUtils.getConnection(); conn.setAutoCommit(false)... 阅读全文
posted @ 2013-12-06 12:42 剑握在手 阅读(2295) 评论(0) 推荐(1) 编辑
摘要:工厂模式:http://baike.baidu.com/view/1306799.htm 参考博客一篇:http://blog.csdn.net/janepen/article/details/6470471 我在一个类中要调用一个Dao的接口,需要先实例一个实现了Dao接口的类的对象。关于这个Dao的实现类我只知道之后有可能会用JDBC实现也有可能用Hibernate实现,为了之... 阅读全文
posted @ 2013-12-06 11:23 剑握在手 阅读(208) 评论(0) 推荐(0) 编辑
摘要:大文本数据Clob,在不同的数据库中类型名不一致,有的是text格式,有的是clob,还有其他一些格式 package test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; ... 阅读全文
posted @ 2013-12-05 15:39 剑握在手 阅读(230) 评论(0) 推荐(0) 编辑
摘要:package test;import java.sql.Connection; import java.util.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;public class SqlDate { /** * @param args * @throws SQLException * @throws ClassNotFoundExcepti... 阅读全文
posted @ 2013-12-05 14:39 剑握在手 阅读(701) 评论(0) 推荐(0) 编辑
摘要:package test;import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;public class CRUD { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { create(); } catch (S... 阅读全文
posted @ 2013-12-05 11:59 剑握在手 阅读(712) 评论(0) 推荐(0) 编辑

返回顶部↑
点击右上角即可分享
微信分享提示