他这里应该没有,什么东西都要多练,练多了你就感觉做这些太简单了,自己就能很快写一个,不需要下载别人的
讲师用的是sqlyog 这个插件,自己取百度下,很多种图形化工具
登陆和注册 是少不了对数据库的操作的 java和数据库的连接就需要jdbc了 你要想追求性能也可以尝试连接池。
你两次的端口号不一样,一个8800,另外一个是8899
getConnection()是DBUtil的静态方法
一个时web运行时的请求和响应
需要的
端口号就和你淘宝一样。只有两边都知道地址才能通信。你收快递不用信息么?你发快递也得知道对面的信息。可能不太恰当。。
public class Ckb_test { public static void main(String[] args) throws SQLException, IOException { // TODO Auto-generated method stub read(); } static void create() throws SQLException, IOException { Connection conn=null; PreparedStatement prest=null; ResultSet resultset=null; try { //2.建立连接 conn=JdbcUtils.getConnection(); //单例设计模式 conn=JdbcUtilsSingle.getInstance().getConnection(); //3.创建语句 String sql="insert into ckb_test(text) values(?)"; prest=conn.prepareStatement(sql); File file=new File("src/cn/com/JDBC/JdbcUtils.java"); Reader reader=new BufferedReader(new FileReader(file)); prest.setCharacterStream(1, reader, (int)file.length()); //4.执行语句 int i=prest.executeUpdate(); reader.close(); System.out.println("i="+i); } finally { JdbcUtils.free(resultset, prest, conn); } } static void read() throws SQLException, IOException { Connection conn=null; Statement st=null; ResultSet resultset=null; try { //2.建立连接 conn=JdbcUtils.getConnection(); //单例设计模式 conn=JdbcUtilsSingle.getInstance().getConnection(); //3.创建语句 st=conn.createStatement(); //4.执行语句 resultset=st.executeQuery("select text from ckb_test"); //5.处理结果 while(resultset.next()) { Clob clob=resultset.getClob(1); Reader reader=clob.getCharacterStream(); //reader=resultset.getCharacterStream(1); File file=new File("JdbcUtils.java"); Writer writer=new BufferedWriter(new FileWriter(file)); char[] buff=new char[1024]; for(int i=0;(i=reader.read(buff))>0;) { writer.write(buff,0,i); } writer.close(); reader.close(); } } finally { JdbcUtils.free(resultset, st, conn); } } } ---------------------------------------------------------------------------------------------------------- public class PictureBlob { public static void main(String[] args) throws SQLException, IOException { read(); } static void create() throws SQLException, IOException { Connection conn=null; PreparedStatement prest=null; ResultSet resultset=null; try { //2.建立连接 conn=JdbcUtils.getConnection(); //单例设计模式 conn=JdbcUtilsSingle.getInstance().getConnection(); //3.创建语句 String sql="insert into blob_test(big_bit) values(?)"; prest=conn.prepareStatement(sql); File file=new File("C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\cxg.jpg"); InputStream in=new BufferedInputStream(new FileInputStream(file)); prest.setBinaryStream(1, in, (int)file.length()); //4.执行语句 int i=prest.executeUpdate(); in.close(); System.out.println("i="+i); } finally { JdbcUtils.free(resultset, prest, conn); } } static void read() throws SQLException, IOException { Connection conn=null; Statement st=null; ResultSet resultset=null; try { //2.建立连接 conn=JdbcUtils.getConnection(); //单例设计模式 conn=JdbcUtilsSingle.getInstance().getConnection(); //3.创建语句 st=conn.createStatement(); //4.执行语句 resultset=st.executeQuery("select big_bit from blob_test"); //5.处理结果 while(resultset.next()) { Blob blob=resultset.getBlob(1); InputStream in=blob.getBinaryStream(); //reader=resultset.getCharacterStream(1); File file=new File("1.jpeg"); OutputStream out=new BufferedOutputStream(new FileOutputStream(file)); byte[] buff=new byte[1024]; for(int i=0;(i=in.read(buff))>0;) { out.write(buff,0,i); } out.close(); in.close(); } } finally { JdbcUtils.free(resultset, st, conn); } } }
一般我们自己用的都是Mysql数据库~毕竟Oracle数据库占用电脑资源比Mysql要多很多~这里建议你用MYsql数据库~而且针对Mysql数据库有一个操作软件叫做Navicat,就是老师所用的那个软件~
数据库中保存文件的话,你可以自己建一个文件夹,然后将图片资源放入该文件夹中~通过程序代码的实现来上传文件夹中的该图片文件即可,希望这回答对你有帮助~
tongwen
\r\n换行
要看具体情况,如果图片量不大,向网站的logo等,可以考虑放数据库,相对更加安全;如果数量比较大,比如各种商品图片等,一般文件夹保存,否则对数据库性能影响较大;
要自己先试试做做嘛,表上来就着急看源码,有问题的话也可以提出来大家一起讨论