新手 jdbc java

更新数据库数据的时候 ,一点要get一个connect,用完立马close关流吗?
可以不可以整个程序声明一个static 的 connect 用到天荒地老 不关流

0
qq_16127313
爱码少年 static Connection 不是安全的做法,不建议这么用
9 个月之前 回复

3个回答

当然可以

到后面还会用到连接池 就是已经连接好的几个对象放在集合中
调用close就是把连接放回到集合里 而不是真正的关闭连接

1

可以啊,有相关的技术了,请查看数据库连接池

1

Connection不是线程安全的,它在多线程环境中使用时,会导致数据操作的错乱和事务提交的混乱。
严禁使用 static Connection !!!
建议研究下spring JdbcTemplate、NamedParameterJdbcTemplate和 apache Dbutils 的实现原理,真正理解后,你会对Connection 该怎么管理有不同的认识!

http://www.cnblogs.com/dolphin0520/p/3920407.html

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
新手 jdbc java
更新数据库数据的时候 ,一点要get一个connect,用完立马close关流吗?rn 可以不可以整个程序声明一个static 的 connect 用到天荒地老 不关流
JAVA新手JDBC问题求教....
[code=Java]package cn.sotraining.test;rnrnimport java.io.*;rnimport java.sql.Connection;rnimport java.sql.DriverManager;rnimport java.sql.PreparedStatement;rnimport java.sql.ResultSet;rnimport java.sql.Statement;rnimport java.util.*;rn/*rn* Created on 2009-6-22rn*/rnrn/**rn* @author XXXrn* @since 1.0rn*rn* TODO 学生成绩管理系统rn* 通过学号查找,修改,删除数据rn* rn*/rnpublic class stuSys rnrn static boolean isDelete = true;rn static boolean isFind = true;rn public static void main(String [] args)//主方法,程序从这里开始运行 rn throws IOException,NumberNotFoundExceptionrn rn int choice;rn dorn stuSys ss = new stuSys();rn System.out.println();rn System.out.println("\t####################################");rn System.out.println();rn System.out.println("\t\t Java学生成绩管理系统1.0");rn System.out.println("\t\t请用学号查找,修改,删除数据");rn System.out.println();rn System.out.println("\t####################################\n");rn System.out.print("1.增加数据:\n"+rn "2.查找数据:\n"+rn "3.删除数据:\n"+rn "4.清除所有数据:\n"+rn "5.把数据全部打印到屏幕\n"+rn "6.把成绩按学号排序\n"+rn "7.修改数据\n"+rn "8.统计已记录成绩学生数\n"+rn "9.关于作者\n"+rn "0.退出程序.\n" +rn "输入:");rn BufferedReader in = //从终rn new BufferedReader( //端接rn new InputStreamReader(System.in));//收数rn String inputLine = in.readLine(); //字选rn choice= Integer.valueOf(inputLine).intValue();//项;rn switch(choice)rn rn case 1: //1.增加数据 rn rn ss.addData();rn System.out.println("增加数据成功.");rn timeOut(1);rn break;rn rn// case 2: //2.查找数据rn// long find = 0;rn// System.out.print("请输入你要查找的学生学号:");rn// BufferedReader inn =rn// new BufferedReader(rn// new InputStreamReader(System.in));rn// String inputLi = inn.readLine();rn// find = Integer.valueOf(inputLi).longValue();rn// ss.findData(find);rn// rn// timeOut(2);rn// break;rn// case 3: //3.删除数据rn// long deleteNumber = 0;rn// System.out.print("请输入你想删除的同学的学号:");rn// BufferedReader bf =rn// new BufferedReader (rn// new InputStreamReader(System.in));rn// String inputL = bf.readLine();rn// deleteNumber = Integer.valueOf(inputL).longValue();rn// ss.deleteData(deleteNumber);rn// if(isDelete)rn// System.out.println("删除数据成功!");rn// timeOut(1);rn// break;rn// case 4: rn// ss.clearData();//4.清除所有数据rn// timeOut(1);rn// break;rn// case 5: rn// print();//5.把数据全部打印到屏幕rn// timeOut(2);rn// break;rn// case 6: rn// ss.numSort();//6.把成绩按学号排序 rn// System.out.println("按照学号从小到大排序成功!\n"+rn// "排序后:\n");rn// print();rn// timeOut(2);rn// break;rn// case 7: rn// ss.rewrite();//7.修改数据rn// timeOut(2);rn// break;rn// case 8: rn// int count = ss.count();rn// System.out.println("共有"+count+"个学生已经记录.");rn// timeOut(2);rn// break;rn// case 9: rn// System.out.print("\t\tXXX\n"+rn// "\t\tXXX\n");rn// timeOut(4);rn// break;rn rn while (choice != 0);rn System.out.println("Bye! ^-^");rn System.exit(0);rn rn rn public void addData()rn rn int num=0;rn String name=null;rn String sex=null;rn int mark=0;rn System.out.print("请依次输入 :学号,姓名,性别,成绩\n" +rn "每项数据请用逗号隔开:");rn tryrn BufferedReader in = //从终rn new BufferedReader ( //端接rn new InputStreamReader(System.in)); //收数 rn String inputLine = in.readLine(); //据rn StringTokenizer str = rn new StringTokenizer(inputLine,", ");//接收的数据用逗号隔开,这个类用来提取每个字符串 rn num = Integer.valueOf(str.nextToken());//学号 rn name = (String)str.nextToken(); //姓名rn sex = (String)str.nextToken(); //性别 rn mark = Integer.valueOf(str.nextToken());//分数 rn rn catch (IOException e)rn catch (NumberFormatException e)rn rn Connection conn = null;rn tryrn rn Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");rn String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";rn conn = DriverManager.getConnection(url,"sa","sa");rn Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);rnrn String sql = "create table d_course (sno int primary key,sname varchar(50),sex varchar(10),score int)";rn stmt.executeUpdate(sql);rnrn rn String insertSql = "insert into d_course values(?,?,?,?)";rn PreparedStatement pstmt = conn.prepareStatement(insertSql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);rn pstmt.setObject(1,num);rn pstmt.setObject(2,name);rn pstmt.setObject(3,sex);rn pstmt.setObject(3,mark);rn int count = pstmt.executeUpdate();rn rnrn rn rn catch (Exception e)rn rn e.printStackTrace();rn rn finallyrn rn tryrn rn conn.close(); rn rn catch (Exception e)rn rn e.printStackTrace();rn rn rn rn rn rn rnrnclass NumberNotFoundException extends Exceptionrn rn public NumberNotFoundException()rn rn[/code]rnrnrn我将原来的一个将数据放入文本保存的学生管理系统,改造成为放入SQL server2000保存rnrn现在将其他功能都注释掉(帖子上省略没写),只留下添加数据的方法进行调试...rnrn编译能正常通过,但是当我输入数据的时候rnrn例如: 1,张三,男,100rnrnJAVA虚拟机报了异常rn[code=Java]rnrn ####################################rnrn Java学生成绩管理系统1.0rn 请用学号查找,修改,删除数据rnrn ####################################rnrn1.增加数据:rn2.查找数据:rn3.删除数据:rn4.清除所有数据:rn5.把数据全部打印到屏幕rn6.把成绩按学号排序rn7.修改数据rn8.统计已记录成绩学生数rn9.关于作者rn0.退出程序.rn输入:1rn请依次输入 :学号,姓名,性别,成绩rn每项数据请用逗号隔开:1,张三,男,100rnjava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).rn at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)rn at com.microsoft.jdbc.base.BasePreparedStatement.validateParameters(Unknown Source)rn at com.microsoft.jdbc.base.BasePreparedStatement.preImplExecute(Unknown Source)rn at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)rn at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)rn at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)rn at cn.sotraining.test.stuSys.addData(stuSys.java:165)rn at cn.sotraining.test.stuSys.main(stuSys.java:59)rn增加数据成功.[/code]rnrn请问大家该如何处理....rnrn到数据库看了下能正常建表,证明数据库连接是没有问题,但就是从键盘输入的数据无法传进数据库
Java新手,简单的JDBC问题?
本人正在学习JAVA,在使用JDBC过程中,很多资料介绍的JDBC连接都是使用JDBC-ODBC方式,不知道怎样直接使用JDBC连接数据库,本人使用的数据库是MSSQL Server。rn请高手指教.rn多谢各位了。
新手求助java连接sql2000的JDBC问题
在下想要用JDBC连接sql2000,驱动已经下载好,三个*.jar文件放在D盘文件夹中,设好了环境变量。也打上了SP4的补丁。rn在EClipse中用以下代码测试时未能成功,请各位大侠帮我看看是哪里出了错,报错如下:rnrnjava.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriverrn at java.net.URLClassLoader$1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:307)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:252)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:169)rn at Apple1.TestJdbc2.(TestJdbc2.java:19)rn at Apple1.TestJdbc2.main(TestJdbc2.java:33)rnrnrnrn以下是我的测试代码rn[code=Java][/code]rnpackage Apple1;rnimport java.sql.*;rnrnpublic class TestJdbc2 rnrn /**rn * @param argsrn */rn rn Connection con;rn Statement st;rn ResultSet rs;rn public TestJdbc2()rn rn tryrn rn String name="com.microsoft.jdbc.sqlserver.SQLServerDriver";rn String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind";rn Class.forName(name);rn con=DriverManager.getConnection(url,"sa","linzong911005");rn System.out.println("连接成功!");rn con.close();rn rn catch (Exception e)rn rn e.printStackTrace();rnrn rn rn rn rn public static void main(String[] args) rn TestJdbc2 cs=new TestJdbc2();rn rn rn
JAVA JDBC中的新手问题 求帮忙
import java.sql.*;rnimport java.awt.event.MouseEvent;rnimport java.awt.event.MouseListener;rnrnimport javax.swing.*;rn //定义一个主界面的类rnpublic class zhujiemian rn rn JFrame JJ=new JFrame();rn JPanel JP=new JPanel();rn JTextField user, password;rn rn rn rn rnpublic void zong() rn rn JJ.setVisible(true);rn JJ.add(JP);rn JJ.setTitle("QQ登录程序");rn JJ.setSize(500,300);rn JJ.setLocation(200,100);rn rn public void denglu() rn JP.setLayout(null);rn JButton JB1=new JButton("登录");rn JButton JB2=new JButton("退出");rn JB1.setBounds(100,150,90,28);rn JB2.setBounds(300,150,90,28);rn JP.add(JB1);rn JP.add(JB2);rn JB1.addMouseListener(new JB1Listener());rn JB2.addMouseListener(new JB2Listener());rn rn rnclass JB1Listener implements MouseListener rn JFrame JF=new JFrame();rn JPanel JP=new JPanel();rn public void mouseReleased(MouseEvent e) rn rn int i;rn shujuku(); //链接数据库 rn i=validate();//测试是否相等rn rn //if (JT1.getText().equals("name")&&JT2.getText().equals("pw")) rn rn JF.setVisible(true);rn JF.setTitle("QQ登录程序");rn JF.setSize(200,400);rn JF.setLocation(1150,30);rn JJ.setVisible(false); rn JF.add(JP);rn JP.setLayout(null);rn JButton jb1=new JButton("空间 ");rn jb1.setBounds(80,60,30,28);rn JP.add(jb1);rn JButton jb2=new JButton("微博 ");rn jb2.setBounds(130,60,30,28);rn JP.add(jb2);rn JLabel jb=new JLabel("未央不见");rn jb.setBounds(90,0,70,70);rn JP.add(jb);rn rn public void mouseClicked(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn rn public void mouseEntered(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn rn public void mouseExited(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn @Overridern public void mousePressed(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn rn rn rn rn class JB2Listener implements MouseListener rn rn public void mouseReleased(MouseEvent e) rn System.exit(0);rn rn public void mouseClicked(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn rn public void mouseEntered(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn rn public void mouseExited(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn @Overridern public void mousePressed(MouseEvent e) rn // TODO Auto-generated method stubrn rn rn rn public void Label() rn JLabel JL1=new JLabel("QQ号码");rn JL1.setBounds(100,28,50,50);rn user=new JTextField(10);rn user.setBounds(165,40,150,25);rn JLabel JL2=new JLabel(" 密码");rn JL2.setBounds(100,68,50,50);rn password=new JTextField(10);rn password.setBounds(165,80,150,25);rn JP.add(JL1);rn JP.add(JL2);rn JP.add(user);rn JP.add(password);rn rn rn rn rn rn rn rn rn //判断 user 与 password是否在数据库中,并匹配user与password rn public int validate()rn rn rn return 0;rn rn rn rn //链接到数据库rn rn public void shujuku()rnrn rn rn rn rn rn public static void main(String args[]) rn zhujiemian z=new zhujiemian();rn rn rn z.Label();rn z.zong();rn z.denglu();rn rn rn rn rnrn 就是在validate()这个方法里面 计算user与pssword是否匹配;rn 直接说算法就好 。然后我自己写代码。谢谢啦!!!!!
java新手请教:jdbc连接问题
程序如下:但为何还是提示错误??rnpackage com.tarena;rnimport java.sql.*;rnpublic class TestCallableStmt rnrn static Connection conn = null;rn //注冊驱动有在其他程序测试过是OK的rn static rn try rn Class.forName("oracle.jdbc.driver.OracleDriver");rn String url = "jdbc:oracle:thin:@localhost:1521:orcl";rn conn = DriverManager.getConnection(url, "scott", "1234");rn catch (ClassNotFoundException | SQLException e) rn e.printStackTrace();rn rn rnrn public static void main(String[] args) rn callSpWithoutOutParam();rn rn rn public static void callSpWithoutOutParam() rn //过程名:insert_stu,表名:student(列名分别为:id, name, age, sex)rn String sql = "call insert_stu(?, ?, ?, ?)";rn try rn CallableStatement callStmt = conn.prepareCall(sql);rn callStmt.setInt(1,2);rn callStmt.setString(2,"Peko");rn callStmt.setInt(3, 24);rn callStmt.setString(4,"M");rn callStmt.execute();rn catch (SQLException e) rn e.printStackTrace();rn rn rn rn[img=https://img-bbs.csdn.net/upload/201308/17/1376702098_60024.jpg][/img]
JDBC连接数据库(新手问题)
不知道哪里出错了rn我数据库没学好 但是想在JAVA方面有所发展 买了本JSP的书rn对于数据库跟网站的连接很迷茫 总觉得很抽象rn按书上的步骤rn下了tomcat6.0.14 MySQL5.2 mysql-connector-java-5.1.3-rc rnEMS SQL manager并添加了相关的环境变量rn在建立连接MySQL数据库实例的时候,出现下面的问题rntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnorg.apache.jasper.JasperException: /jdbc_con.jsp(2,0) The value for the useBean class attribute classes.JDBCCon is invalid.rn org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)rn org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)rn org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)rn org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1200)rn org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1155)rn org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2338)rn org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2388)rn org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2394)rn org.apache.jasper.compiler.Node$Root.accept(Node.java:489)rn org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2338)rn org.apache.jasper.compiler.Generator.generate(Generator.java:3374)rn org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)rn org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrnrnnote The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.rnrn在网上查了半天,还是不知道哪里出了问题rn大家帮帮我吧 谢谢拉 我是为了解决这个问题刚来到这个社区 还请各位不吝赐教啊 rnrn
新手~关于JDBC的一些问题
最近在学习数据库编程,遇到几个问题;rnrn1. 可以连接数据库而且也可以顺利的遍历数据库指定表中的数据(就是写一个循环的方法) 但是总是琢磨不出来怎么拿出单条的记录;最好是能给我简单示范一下 嘿嘿~rnrn2. 现在的很多注册的原理 是不是用户输入自己将要注册的用户名和密码 然后相当于用insert插入到数据库中的一个表里面?说说大家简单的想法和实现的代码。rnrn谢谢大家了~
JDBC实例,新手的过度
一个JDBC实例,数据库分别为SQLServer和MYSQL简单易懂,新手的过度。
新手jsp.关于jdbc
windows 2000 serverrnmyeclipse tomcat 5rnoracle 8rnrn我在%tomcatpath%\commom\lib\rn放了classes12.ziprn运行jsprnjava.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver rnrn
JDBC新手试练
[size=medium] 刚刚接触mysql,并且已经开始学习JDBC编程,以清晰方便的对数据库进行操作,避免了命令行的麻烦和冗余。[/size] [size=medium] 才学习了一些JDBC对数据库操作的简单应用,主要有连接数据库、对数据库进行增、删、改、查和事务处理机制。[/size] [code="java"]//连接数据库 private void...
新手的JDBC问题
//一个连接数据库的方法,桥连可以直连就不行,我少写什么了,请指点?rn public static synchronized Connection getConnection() throws Exception rn Connection conn = null;rn String name = "oracle.jdbc.driver.OracleDrrver";rn String url = "jbdc:oracle:thin:@localhost:1521:oracle9i";rn String user = "student";rn String password = "student";rn //String name = "sun.jdbc.odbc.JdbcOdbcDriver";rn //String url = "jdbc:odbc:database";rn try rn Class.forName(name).newInstance();rn conn = DriverManager.getConnection(url,user,password);rn rn catch (Exception e) rn e.printStackTrace();rn rn return conn;rn
JDBC新手快速入门
jdbc实现步骤 首先导入数据库厂商的jar包! import java.sql.*; 第一步加载驱动 Class.forName("com.mysql.jdbc.Driver") 第二步创建连接对象 Connection con =DriverManger.getconnection("jdbc:mysql://localhost:3306/studb","root",""); 第三步创建处理对象 Statement st=con.createStatement(); 第四步相应处理
jdbc新手的一个问题
我是JDBC新手,刚学,想做做试验。例如下面的代码:rnrn……rnResultSet rs = stmt.executeQuery("select * from tablename");rn……rnrn怎样能在控制台打印出rs中的所有内容呢?rnrn或者怎样知道我是否成功将tablename中的数据全都装入rs中了呢?rnrn谢谢了……
新手jdbc问题
连接sql server 2000rn报错 请教一下 代码如下rntryrn rn[color=#FF0000] Class.forName("com.Microsoft.jdbc.sqlserver.SQLServerDriver");[/color]rn ct = DriverManager.getConnectionrn ("jdbc:Microsoft:sqlserver://127.0.0.1:1433;databaseName = master");rn ps = ct.prepareStatement("select * from emp");rn rs = ps.executeQuery();rn while(rs.next())rn rn String name = rs.getString(2);rn float f = rs.getFloat(6);rn int i = rs.getInt(8);rn rn System.out.println(name+" "+f+" "+i);rn rn rn catch(Exception e)rn rn e.printStackTrace();rn rn finallyrn rn try rn rs.close();rn ps.close();rn ct.close();rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrn报错:rnjava.lang.ClassNotFoundException: com.Microsoft.jdbc.sqlserver.SQLServerDriverrn at java.net.URLClassLoader$1.run(URLClassLoader.java:200)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:188)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:307)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:252)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:169)rn at com.jdbctoodbc.Test3.main(Test3.java:19)rnException in thread "main" java.lang.NullPointerExceptionrn at com.jdbctoodbc.Test3.main(Test3.java:40)rnrnrn就是颜色字体那一行rn是哪里写错了吗?谢谢
新手jdbc的一个问题
我想把一个图片存在进sql数据库的一个字段里 这个字段应该是什么类型的啊? 谢谢回答 !
新手求教JDBC
请问下面这段代码能否用JDBC来完成([color=#FF0000]主要是指定中文搜索引擎[/color]):rnrnmysql> CREATE TABLE t_fulltext(rn -> `id` int(11) DEFAULT NULL,rn -> `name` varchar(512) DEFAULT NULL,rn -> `content` text,rn -> FULLTEXT KEY idx_name(name),rn -> FULLTEXT KEY idx_content(content) [color=#FF0000]WITH PARSER ngram[/color]rn -> ) [color=#FF0000]ENGINE=InnoDB DEFAULT CHARSET=utf8;[/color]rnrn还是只能用控制台命令来完成?类似还有数据库备份到一个文件,还原数据库,这些JDBC能做到吗?
java和jdbc
本实例程序中包含了全面的java常用语法和Demo以及jdbc访问数据库的常用实例Demo.
java jdbc
java jdbc 的简单练习,rnimport java.sql.*;rnpublic class JDBC rn public static void main(String args[])rn tryClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn rn catch(ClassNotFoundException e)rn System.out.println(e);rn //建立桥接器rn tryrn Connection con=DriverManager.getConnection("jdbc:odbc:sss", "", ""); rn rn Statement sql=con.createStatement();rn rn [color=#FF0000] ResultSet rs=sql.executeQuery("SELECT * FROM table");[/color]rn rn double sum=0;rn int count=0;rn while(rs.next())rn count++;rn String id=rs.getNString(1);rn String name=rs.getString(2);rn double a=rs.getDouble(3);rn sum=sum+a;rn System.out.printf("%s %s %f\n", id,name,a);rn rn System.out.println(sum/count);rn con.close();rn rn rn catch(SQLException e)rn System.out.println("h");rn rn rnrn ResultSet rs=sql.executeQuery("SELECT * FROM table")我测试应该是这一句抛出了异常但不知道为什么rn[img=https://img-bbs.csdn.net/upload/201805/17/1526566789_585467.png][/img]rn[img=https://img-bbs.csdn.net/upload/201805/17/1526566802_736212.png][/img]rn[img=https://img-bbs.csdn.net/upload/201805/17/1526566814_98345.png][/img]
java的jdbc
mport java.sql.*; class database { public static void main(String args[]) { try{ ///3个方法注册驱动 //1 最好 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //2 DriverManger.re(new odbc.jdbc.); //3 System.setproperty(); //建立连接
Java JDBC
Java JDBC数据库编程,英文版本
Java jdbc
java的JDBC介绍
Java and JDBC
NIIT第二模块考试java部分的ppt
java and JDBC!
java 中数据库的应用很广泛,请各位高手指教:JDBC从什么地方下载,怎样安装,谢谢!!rn如果我想连接Access 数据库怎么连?rn
Java之JDBC
NULL 博文链接:https://ldaolong.iteye.com/blog/2146157
Java——》JDBC
版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者。 https://blog.csdn.net/weixin_43453386/article/details/89669601 Java——》JDBC 1、都是接口(interface)2、不同继承3、不同方法1) Statement接口提供了执行语句和获取结果的基本方法2)PreparedStatem...
新手提问:jdbc连接问题!!!
jdbc连接老报错:java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver 我已经设置了classpath=D:\Oracle\Ora81\jdbc\lib\classes12.zip(jar),都不对,不知道为什么?!挺着急的,谢谢大家帮忙!
JDBC/JSP/Servlet新手问
这样用反射从结果集中提取JavaBean会影响效率吗?rn /**rn * 从结果集中取出游标当前所指的记录,封装为JavaBeanrn * @param beanClassrn * @param rsrn * @returnrn * @throws IllegalAccessExceptionrn * @throws InstantiationExceptionrn * @throws InvocationTargetException rn * @throws SQLExceptionrn */rn public static B extractOneBean(Class beanClass, ResultSet rs) rn throws SQLException, rn IllegalAccessException, rn InstantiationException, rn InvocationTargetException rn B bean = beanClass.newInstance();rn Method[] methods = beanClass.getMethods();rn rn String methodName;rn int clmIndex;rn Class parType;rn Object parValue;rn rn for (Method method : methods) rn // filter methodrn methodName = method.getName();rn if (!methodName.startsWith("set")) rn continue;rn rn rn try rn clmIndex = rs.findColumn(methodName.substring(3));rn catch (SQLException e) rn continue;rn rn rn // invoke setterrn parType = method.getParameterTypes()[0];rn parValue = null; rn if (parType == String.class) rn parValue = rs.getString(clmIndex);rn else if (parType == int.class) rn parValue = rs.getInt(clmIndex);rn else if (parType == Date.class) rn parValue = rs.getDate(clmIndex);rn rn rn if (parValue != null) rn method.invoke(bean, parValue); rn rn rn rn return bean;rn rn rn /**rn * 取出结果集中的所有记录,封装为JavaBean Listrn * @param beanClassrn * @param rsrn * @return rn * @throws IllegalAccessExceptionrn * @throws InstantiationExceptionrn * @throws InvocationTargetException rn * @throws SQLExceptionrn */rn public static List extractAllBeans(Class beanClass, ResultSet rs)rn throws SQLException,rn IllegalAccessException,rn InstantiationException,rn InvocationTargetException rn // create bean listrn ArrayList beanList = new ArrayList();rn rs.last();rn int rowCount = rs.getRow();rn for (int i = 0; i < rowCount; i++) rn beanList.add(beanClass.newInstance());rn rn rn Method[] methods = beanClass.getMethods();rn String methodName;rn int clmIndex;rn Class parType;rn Object parValue;rn rn for (Method method : methods) rn // filter methodrn methodName = method.getName();rn if (!methodName.startsWith("set")) rn continue;rn rn rn try rn clmIndex = rs.findColumn(methodName.substring(3));rn catch (SQLException e) rn continue;rn rn rn // invoke setter on each beanrn rs.first();rn parType = method.getParameterTypes()[0];rn for(int i = 0; i < rowCount; i++) rn parValue = null;rn if (parType == String.class) rn parValue = rs.getString(clmIndex);rn else if (parType == int.class) rn parValue = rs.getInt(clmIndex);rn else if (parType == Date.class) rn parValue = rs.getDate(clmIndex);rn rn rn if (parValue != null) rn method.invoke(beanList.get(i), parValue);rn rn rn rs.next();rn rn rn rn return beanList;rn
新手问题JDBC driver is not on the CLASSPATH
我用SQL SERVER 2000与weblogic配置连接池出现了JDBC driver is not on the CLASSPATHrn错误rn我看了一下别人的文章说什么加载驱动rn请各位高手帮我解决一下rn请详细说明谢谢!rn
关于JDBC的问题:新手求教
同样的数据,通过cmd插入ORACLE数据库能正常的插入,但通过JDBC插入会报 :值大于为此列指定的允许精度的错误,请各位大神帮我看看,十分感谢!!rnpackage com.study.jdbc.emppo;rnrnpublic class Emp rn private int empno;rn private String ename;rn private String job;rn private int mgr;rn private String hiredate;rn private int sal;rn private int comm;rn private int deptno;rnrn public int getEmpno() rn return empno;rn rnrn public void setEmpno(int empno) rn this.empno = empno;rn rnrn public String getEname() rn return ename;rn rnrn public void setEname(String ename) rn this.ename = ename;rn rnrn public String getJob() rn return job;rn rnrn public void setJob(String job) rn this.job = job;rn rnrn public int getMgr() rn return mgr;rn rnrn public void setMgr(int mgr) rn this.mgr = mgr;rn rnrn public String getHiredate() rn return hiredate;rn rnrn public void setHiredate(String hiredate) rn this.hiredate = hiredate;rn rnrn public int getSal() rn return sal;rn rnrn public void setSal(int sal) rn this.sal = sal;rn rnrn public int getComm() rn return comm;rn rnrn public void setComm(int comm) rn this.comm = comm;rn rnrn public int getDeptno() rn return deptno;rn rnrn public void setDeptno(int deptno) rn this.deptno = deptno;rn rnrnrnrnpackage com.study.jdbc.emppo;rnrnimport java.sql.Connection;rnimport java.sql.PreparedStatement;rnimport java.sql.SQLException;rnrnimport com.study.jdbc.po.GetConnection;rnrnpublic class EmpDao rn rn private Connection conn = null;rn public EmpDao()rn //初始化与数据库的连接 rn GetConnection getConn = new GetConnection();rn conn = getConn.getConnection();rn rn // 添加员工信息rn public int insertEmpInfo(Emp emp)throws SQLExceptionrn String sql = "INSERT INTO t_emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)VALUES(?,?,?,?,TO_DATE(?,'YYYY-MM-DD'),?,?,?)";rn PreparedStatement stmt = conn.prepareCall(sql);rn stmt.setInt(1, emp.getEmpno());rn stmt.setString(2, emp.getEname());rn stmt.setString(3, emp.getJob());rn stmt.setInt(4, emp.getMgr());rn stmt.setString(5, emp.getHiredate());rn stmt.setInt(6, emp.getSal());rn stmt.setInt(7, emp.getComm());rn stmt.setInt(8, emp.getDeptno()); rn System.out.println(sql);rn return stmt.executeUpdate();rn rn rnrnrnrnpackage com.study.jdbc.emppo;rnrnimport java.sql.SQLException;rnrnpublic class EmpDaoTest rnrn private EmpDao empDao = new EmpDao();rn public void testInsertEmpInfo() rn try rn Emp emp = new Emp();rn emp.setDeptno(60);rn emp.setComm(200);rn emp.setEmpno(1111);rn emp.setEname("wsdf");rn emp.setJob("学生");rn emp.setMgr(33514);rn emp.setSal(3500);rn emp.setHiredate("2012-11-02");rn int refRows = empDao.insertEmpInfo(emp);rn System.out.println("refRows->"+refRows);rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn rn public static void main(String[] args) rn EmpDaoTest test = new EmpDaoTest();rn test.testInsertEmpInfo();rnrn rnrnrnrnpackage com.study.jdbc.po;rnrnimport java.sql.Connection;rnimport java.sql.DriverManager;rnimport java.sql.SQLException;rnimport java.sql.Statement;rnrnpublic class GetConnection rn private Connection conn;rn private static Connection conn2;rn public Connection getConnection() rn try rn Class.forName("oracle.jdbc.OracleDriver");rn // 驱动管理器在jvm中寻找已注册的数据库的驱动类(OracleDriver类型的运行期对象Class)rn // 并且创建该驱动类的实例,并调用连接方法创建一个和该驱动类指向的数据库的连接对象rn String url = "jdbc:oracle:thin:@localhost:1521:orcl";rn String user = "scott";rn String password = "tiger";rn conn = DriverManager.getConnection(url, user, password);rnrn System.out.println(conn != null ? "连接成功" : "连接失败");rn conn.setAutoCommit(false);rn //Statement stmt = conn.createStatement();rn catch (ClassNotFoundException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rnrn return conn;rn rn
新手JDBC ORACLE的连接问题
import java.sql.*;rnrnpublic class Base rnrn rn public static void main(String[] args) rn rnrn rn static void test()throws SQLExceptionrn DriverManager.registerDriver(new oracle.jdbc.OracleDriver());rn Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");rn Statement st = con.createStatement();rn ResultSet rs = st.executeQuery("select * from emp");rn while(rs.next())rn System.out.println(rs);rn rn rs.close();rn st.close();rn con.close();rn rn rnrnrn
新手问题,关于JDBC驱动!!!
在用JB开发的时候..rn 需要JDBC驱动链接数据库,安装了C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC. 但是还是提示,找不到驱动..rn 请问怎么在系统中配置驱动程序呀??
新手上路之oracle JDBC 笔记
jdbc: java database connectivity java 与数据库的连接.一、角色分类 服务器 (db): a)、接收 sql b)、执行 sql c)、返回结果 客户端 (java): a)、接收数据 b)、组装sql c)、发送SQL(与数据库建立联系) d)、分析结果二、面向接口编程 1、java 制定标准 ,不同的数据库厂商实现 接口即可。java 中提供的接口 ja
jdbc连接问题,新手提问!!!
//我的数据库连接类:(main()用于测试)rnpackage bookshop;rnimport java.sql.*;rnimport java.io.*;rnpublic class DBConnrnrn //String sDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";rn String sDBDriver="net.sourceforge.jtds.jdbc.Driver";rn //String sConnStr="jdbc:microsoft:sqlserver://192.168.150.190:1433;DatabaseName=bookshop";rn String sConnStr="jdbc:jtds:sqlserver://192.168.150.190:1433/bookshop";rn private Connection conn=null;rn private Statement stmt=null;rn ResultSet rs=null;rn rn public DBConn()rn rn tryrn //注册数据库驱动程序rn Class.forName(sDBDriver);rn System.out.println("Success loading Mysql Driver!");rn rn //catch(java.lang.ClassNotFoundException e)rn //rn // System.err.println(e.getMessage());rn //rn catch(Exception e)rn rn System.out.print("Failed to load driver!");rn e.printStackTrace();rn rn rn //建立数据库连接及定义数据查询rn public ResultSet executeQuery(String sql)rn rn rs=null;rn tryrn rn conn=DriverManager.getConnection(sConnStr,"sa","sa");//创建数据库联接对象rn stmt=conn.createStatement();rn rs=stmt.executeQuery(sql);rn rn catch(SQLException ex)rn rn System.err.println("aq.executeQuery:"+ex.getMessage());rn rn return rs;rn rn //定义数据操作rn public void executeUpdate(String sql)rn rn stmt=null;rn rs=null;rn tryrn rn conn=DriverManager.getConnection(sConnStr,"sa","");//创建数据库联接对象rn stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);rn stmt.executeUpdate(sql);rn stmt.close();rn conn.close();rn rn catch(SQLException ee)rn rn System.err.println("aq.executeUpdate:"+ee.getMessage()); rn rn rn //关闭数据库联接rn public void closeStmt()rn rn tryrn rn stmt.close();rn rn catch(SQLException e)rn rn e.printStackTrace();rn rn rn public void closeConn()rn rn tryrn rn conn.close();rn rn catch(SQLException e)rn rn e.printStackTrace();rn rn rn rn public static void main(String arg[]) rn rn String userid="sjl";rn String password="sjl";rn tryrn rn DBConn dbConn=new DBConn(); rn String sql="select * from [users] where USER_ID='"+userid+"' and USER_PASSWORD='"+password+"'"; rn ResultSet rs=dbConn.executeQuery(sql); rn if(rs.next())rn rn System.out.println("Successful!");rn rn rn catch(SQLException e)rn rn System.out.print(e);rn rn rnrn---------------------------------------------------rneclipse下debug出现如下错误:rnjava.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driverrn at java.net.URLClassLoader$1.run(URLClassLoader.java:199)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:187)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:289)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:235)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:141)rn at bookshop.DBConn.(DBConn.java:18)rn at bookshop.DBConn.main(DBConn.java:95)rnaq.executeQuery:No suitable driverrnrnrn
新手问题 JDBC连接数据库出错.
把书上打开数据库的类改造了一下,不能用了,错误提示如下rnException in thread "main" java.lang.NullPointerExceptionrn at opendb.opendb.executeQuery(opendb.java:45)rn at opendb.opendb.main(opendb.java:15)rnERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2rnJDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]rn本来书上的类没有main,我为了测试是否成功打开数据库,加了这个函数,根据错误提示好像是说rn Statement stmt=conn.createStatement();rn rs=stmt.executeQuery(sql);rn这两行出错了,我是刚刚学这个东西,实在找不出来错误的原因,大家帮帮忙啊.谢谢rnrn这个类的源码如下:rnpackage opendb; //定义包opendbrnimport java.sql.*; //引入java.sql.*rnrnimport javax.sql.*;rnimport javax.naming.*;rnrnpublic class opendb rnrn static Connection conn=null;rn static ResultSet rs=null;rnrn public static void main(String[] args)rn rn String sql="select * from IDinfo";rn ResultSet temp=executeQuery(sql);rn try rn if(rs.next())rn System.out.println(temp.getString(1));rn catch (SQLException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn public opendb() rn rn tryrn rn Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn conn = DriverManager.getConnection("jdbc:odbc:flysky","sa","");rn rn catch(Exception exc)rn rn exc.printStackTrace();rn rn rnrn //定义执行sql语句的函数rn public static ResultSet executeQuery(String sql) rn rn rs=null;rn rn tryrn rn Statement stmt=conn.createStatement();rn rs=stmt.executeQuery(sql);rn rn catch (SQLException ex)rn rn System.err.println("aq.executeQuery:"+ex.getMessage());rn rn rn return rs;//返回sql语句的执行结果rn rnrnrn
新手提问关于 JAVABEAN 和 JDBC
先问一个关于JDBC的 rn我是用MS SQL 然后我去下了它的驱动放在common\librn也试了放在WEB-INF\lib下rn然后我用如下的语句访问会出错rn rnClass.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();rn Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=test","sa","sa");rnrnrn出错的信息如下rnexception rnrnjavax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.rn org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)rn org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:795)rn org.apache.jsp.Mssql_jsp._jspService(Mssql_jsp.java:105)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rnrnrnroot cause rnrnjava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.rn com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)rn com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)rn com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)rn com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)rn com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)rn com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)rn java.sql.DriverManager.getConnection(Unknown Source)rn java.sql.DriverManager.getConnection(Unknown Source)rn org.apache.jsp.Mssql_jsp._jspService(Mssql_jsp.java:79)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rn rn但如果我用rnClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn Connection con=DriverManager.getConnection("jdbc:odbc:MSSQL","sa","sa");rn这用来访问就可以了rn但我相用JDBC来访问 帮帮我rnrnrn在问一个rn我做了个JSP + JAVABEAN 的练习rn其中有两个有BEANrn一个是User (接受formr的数据)rn一个是Adduser(入数据库)rn只要一调用里面的UserRegist的REGIST就出错rnuser是可以的rn我都试了rn就是Adduser可能有点问题 但我一直调没调出来请各位帮帮忙rn以下是Adduser.classrnrnpackage test;rnimport sun.jdbc.odbc.JdbcOdbcDriver;rnimport java.sql.*;rnrnpublic class Adduser rn rn private User user;rn private Connection con;rn rn public void UserRegist()rn rn tryrn rn Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");rn con=DriverManager.getConnection("jdbc:odbc:MSSQL","sa","sa");rn Statement stmt=con.createStatement();rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rn rn public void setUser(User user)rn rn this.user=user; rn rn rn public void regist()throws Exceptionrn rn String reg = "insert into user valuse(?,?,?,?,?,?,?)";rn rn tryrn rn PreparedStatement pstmt = con.prepareStatement(reg);rn pstmt.setString(1,"58");rn pstmt.setString(2,user.getUsername());rn pstmt.setString(3,user.getPassword());rn pstmt.setString(4,user.getSex());rn pstmt.setString(5,user.getPho());rn pstmt.setString(6,user.getEmail());rn pstmt.setString(7,"rerer");rn pstmt.executeUpdate();rn rn catch(Exception e)rn rn e.printStackTrace();rn throw e;rn rn rn rnrnrnrnrn以下是User.classrnrnrnpackage test;rnrnpublic class User rn rn private String username;rn private String password;rn private String sex;rn private String pho;rn private String email;rn rn public String getUsername()rn rn return this.username;rn rn rn public String getPassword()rn rn return this.password;rn rn rn public String getSex()rn rn return this.sex;rn rn rn public String getPho()rn rn return this.pho;rn rn rn public String getEmail()rn rn return this.email;rn rn rn public void setUsername(String username)rn rn this.username=username;rn rn rn public void setPassword(String password)rn rn this.password=password;rn rn rn public void setSex(String sex)rn rn this.sex=sex;rn rn rn public void setPho(String pho)rn rn this.pho=pho;rn rn rn public void setEmail(String email)rn rn this.email=email;rn rn rnrnrnrn以下是user.jsprnrn<%@ page language="java" pageEncoding="GB2312" %>rnrnrnrn Lomboz JSPrnrnrnrn rnusername: rnpassword: rnsex: rnpho: rnemail: rnrnrnrnrnrnrnrn以下是adduser.jsprnrn<%@ page language="java" pageEncoding="GB2312" import="java.sql.*"%>rnrnrnrnrnrnrn Lomboz JSPrnrnrnrn<%rnadduser.setUser(user);rnout.println(user.getUsername());rnadduser.regist(); 这个一调用就出错rnout.println("ok");rn%>rnrnrnrnrn出错信息rnrnorg.apache.jasper.JasperExceptionrn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rnrnrnroot cause rnrnjava.lang.NullPointerExceptionrn test.Adduser.regist(Adduser.java:36)rn org.apache.jsp.adduser_jsp._jspService(adduser_jsp.java:85)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:856)rnrnrnrnrnrnrn
新手:jdbc连接postgresql的问题
本人菜鸟,刚接触PSQL没几天,想写个留言板,需要连接数据库,看视频里写的是用Oracle,有这么一句代码:rnrn String driver="oracle.jdbc.driver.OracleDriver";rn rn应该是用来连接Oracle类库的,那么想用PSQL该怎么写这句话啊? PSQL的驱动必须放在Java\jdk1.6.0_10\jre\lib\ext目录下吗? 拜托各位了!需要把那句代码帮忙剖析一下,在此多谢了!我也没多少分了 拜托了
【Java】Java中的JDBC
【什么叫JDBC?】 JDBC为Java开发者使用数据库提供了统一编程接口,它由一组Java类和接口组成。是Java程序与数据库系统通信的标准 API。JDBC  API使得开发人员可以使用纯java的方式来连接数据库,并执行操作。 【JDBC的操作】 在进行JDBC 操作的时候可以按照以下的步骤完成: 1、加载数据库驱动程序,加载的时候需要将驱动程序配置到class
【Java】Java的JDBC编程
JDBC的创建流程
【Java】Java之JDBC编程
什么是JDBC? JDBC(java Database connectivity,java数据库连接),是一种于执行SQL语句的Java API,为多种关系型数据库提供了统一的访问方式。 JDBC工作原理 JDBC主要包含一些通用的接口类,真正的数据库访问操作的实现是由各自数据库厂商提供的,我们把厂商提供的特定的数据库的访问API成为数据库的JDBC驱动。 JDBC步骤 a. 准备数据库驱动包(...
相关热词 c# 线程顺序 c#昨天当前时间 c# 多进程 锁 c#mysql图片存取 c# ocx 委托事件 c# 读取类的属性和值 c# out 使用限制 c#获取url的id c#怎么进行分页查询 c# update 集合