Mysql与Oracle的JDBC连接

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lsh_li/article/details/83322385
Oracle连接:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:SXT","scott","tiger");

Mysql连接:

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/student?user=root&password=root");
展开阅读全文

jdbc连接oracle的问题

05-16

已copy classes12.jar至%java_home%/lib/ 下,并在claaspath中提明rn然后代码如下:rnimport java.sql.*;rnpublic class DBTest rn public static void main(String[] args) throws Exception rn Class.forName("oracle.jdbc.OracleDriver");rn String url = "jdbc:oracle:thin:@134.201.26.169:1521:ibss";rn Connection conn=DriverManager.getConnection(url,"jk_112","jk2050930");rn ResultSet rs=null;rn PreparedStatement pstmt=null;rn String sql="select telephone,subname from inf_112_info where produce_id = '401'";rn try rn pstmt=conn.prepareStatement(sql);rn pstmt.setString(1,"10");rn rs=pstmt.executeQuery();rn while (rs.next()) rn System.out.println(rs.getString("telephone"));rn System.out.println(rs.getString("subname"));rn rn rn finally rn if (rs!=null) rn try rs.close(); catch(SQLException e) ;rn rn if (pstmt!=null) rn try pstmt.close(); catch(SQLException e) ;rn rn if (conn!=null) rn try conn.close(); catch(SQLException e) ;rn rn rn rn rn rn报错如下:rnException in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.OracleDrnriverrn at java.net.URLClassLoader$1.run(URLClassLoader.java:198)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:186)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:299)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:272)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:255)rn at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:140)rn at DBTest.main(DBTest.java:4)rnrnrn什么原因还是oracle的jdbc问题啊,谢谢帮助!!!!!!!!!!!!! 论坛

JDBC连接oracle的问题!

11-20

源码如下:rnimport java.sql.*;rnpublic class ConnectDBrnrn Connection conn=null;rn Statement st=null;rn ResultSet rs=null;rn String driver="oracle.jdbc.driver.oracledriver";rn String url="jdbc:oralce:thin:@jujumao:1521:wzacs";rn String user="wzacs";rn String password="36987asd";rn String sql="select * from student";rn public void doConnect()rn rn tryrn rn Class.forName(driver).newInstance();rn System.out.println("加载驱动成功");rn conn=DriverManager.getConnection(url,user,password);rn System.out.println("连接数据库成功");rn st=conn.createStatement();rn rs=st.executeQuery(sql);rn while(rs.next())rn rn System.out.println("------记录------");rn System.out.println("学号"+rs.getString("sno"));rn System.out.println("姓名"+rs.getString("sname"));rn System.out.println("性别"+rs.getString("ssex"));rn System.out.println("年龄"+rs.getInt("sage"));rn System.out.println("专业"+rs.getString("sdept"));rn rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rnrn public static void main(String[] args)rn rn ConnectDB aa=new ConnectDB();rn aa.doConnect();rn rnrn编译通过了 不过运行是报错如下:rnimport java.sql.*;rnpublic class ConnectDBrnrn Connection conn=null;rn Statement st=null;rn ResultSet rs=null;rn String driver="oracle.jdbc.driver.oracledriver";rn String url="jdbc:oralce:thin:@jujumao:1521:wzacs";rn String user="wzacs";rn String password="36987asd";rn String sql="select * from student";rn public void doConnect()rn rn tryrn rn Class.forName(driver).newInstance();rn System.out.println("加载驱动成功");rn conn=DriverManager.getConnection(url,user,password);rn System.out.println("连接数据库成功");rn st=conn.createStatement();rn rs=st.executeQuery(sql);rn while(rs.next())rn rn System.out.println("------记录------");rn System.out.println("学号"+rs.getString("sno"));rn System.out.println("姓名"+rs.getString("sname"));rn System.out.println("性别"+rs.getString("ssex"));rn System.out.println("年龄"+rs.getInt("sage"));rn System.out.println("专业"+rs.getString("sdept"));rn rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rnrn public static void main(String[] args)rn rn ConnectDB aa=new ConnectDB();rn aa.doConnect();rn rnrn编译通过后运行有一下问题:rnException in thread "main" java.lang.UnsupportedClassVersionError: ConnectDB (Unrnsupported major.minor version 49.0)rn at java.lang.ClassLoader.defineClass0(Native Method)rn at java.lang.ClassLoader.defineClass(Unknown Source)rn at java.security.SecureClassLoader.defineClass(Unknown Source)rn at java.net.URLClassLoader.defineClass(Unknown Source)rn at java.net.URLClassLoader.access$100(Unknown Source)rn at java.net.URLClassLoader$1.run(Unknown Source)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClass(Unknown Source)rn at java.lang.ClassLoader.loadClassInternal(Unknown Source)rn请问是什么原因啊?rn谢谢个位高手了!!!!! 论坛

JDBC连接oracle程序错误

02-21

小弟最近写了一个jdbc连接oracle的程序,在myeclipse里一执行就出现下面的错误。跪求大侠帮忙,下面是小弟的代码和错误界面;rnpackage util;rnrnimport java.sql.Connection;rnimport java.sql.DriverManager;rnimport java.sql.ResultSet;rnimport java.sql.Statement;rnpublic class ConnectionJDBC_01 rnpublic static void main(String[]args)rnString driver="oracle.jdbc.driver.OracleDriver";rnString url="jdbc:oracle:thin:@localhost:1521:orcl";rnString username="hrsoft";rnString password="hrsoft";rntryrn Class.forName(driver).newInstance();rn rn Connection conn=DriverManager.getConnection(url,username,password);rn Statement sta=conn.createStatement();rn String sql="select * from students where id=1";rn ResultSet re=sta.executeQuery(sql);rn while(re.next())rn System.out.println(re.getInt(1));rn System.out.println(re.getString(2));rn rn re.close();rn sta.close();rn conn.close();rncatch(Exception e)rn e.printStackTrace();rnrnrnrn下面是出现错误的信息,rn#rn# An unexpected error has been detected by Java Runtime Environment:rn#rn# Internal Error (exceptions.cpp:367), pid=224, tid=4368rn# Error: ExceptionMark destructor expects no pending exceptionsrn#rn# Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing windows-x86)rn# An error report file with more information is saved as:rn# E:\Documents and Settings\Administrator\Workspaces\MyEclipse 8.5\HRsoft_1_0.1\hs_err_pid224.logrn#rn# If you would like to submit a bug report, please visit:rn# http://java.sun.com/webapps/bugreport/crash.jsprn#rn 论坛

没有更多推荐了,返回首页