Matlab通过JDBC连接Oracle数据库

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

Matlab通过JDBC连接Oracle数据库

1. 找到jdbc的驱动程序文件并复制

位置在Oracle安装基目录\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar,然后将它复制到
matlab安装目录的java子目录..\MATLAB\R2016a\java\jar\toolbox下;

2. 修改matlab的classpath文件

该文件在..\MATLAB\R2013a\toolbox\local\classpath.txt,于结尾添加一
行:$matlabroot/java/jar/toolbox/ojdbc6.jar

3. 建立连接的命令并测试

在MatLab命令行窗口输入以下数据库连接字符串:

conn = database('sid_name','username','password','driverName','连接字符串')

sid_name:这里不是services_name
username:用户名
password:密码
driverName:驱动名称—’oracle.jdbc.driver.OracleDriver’
连接字符串:‘jdbc:oracle:thin:@localhost:1521:sid_name’

注意:jdbc连接数据库的时候,需要使用数据库的sid_name,而不是数据库的services_name。
查询sid_name指令:

select INSTANCE_NAME from v$instance;

4. 通过ping命令查看连接状况

ping(conn_jdbc)     %jdbc方式连接时

5. 常见连接错误

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 

修改方案就是检查sid_name是否写错了。

【参考文献】
1. https://www.cnblogs.com/imyao/p/5578476.html
2. https://blog.csdn.net/zhangzl1012/article/details/50752572
3. https://zhidao.baidu.com/question/177221503150372404.html

展开阅读全文

Java通过JDBC连接oracle数据库的问题

09-30

以前在JDK131做的一个小程序,连接oracle8.1.6,很正常,现在用JDK141编译没问题,执行则报错(在editplus下编译,执行)rnrn---------- Java ----------rn没有相应的数据库驱动:oracle.jdbc.driver.OracleDriverrn数据库连接出错:No suitable driverrnjava.lang.NullPointerExceptionrn at myFirstJDBC.main(myFirstJDBC.java:39)rnException in thread "main" rn输出完成 (耗时 0 秒) - 正常终止rnrnrnrn源代码如下:rnrnimport java.io.*;rnimport java.sql.*;rnrnpublic class myFirstJDBC rnrn public static void main(String[] args) rn rn Connection con=null;rn PreparedStatement ps=null;rn ResultSet rs=null;rnrn try //载入数据库驱动类库rn rn Class.forName ("oracle.jdbc.driver.OracleDriver"); //rn rn catch (ClassNotFoundException ce)rn rn //System.out.println("SQLException:"+ce.getMessage());rn System.out.println("没有相应的数据库驱动:"+ce.getMessage());rn rn rn try rn rn con=DriverManager.getConnection("jdbc:oracle:thin:@10.64.21.14:1521:baa","baa","baa");//通过rn rn catch (SQLException e)rn rn System.out.println("数据库连接出错:"+e.getMessage());rn rn rn rn try //执行sql语句rn rn String sql="select * from a where a_id=2";rn ps=con.prepareStatement(sql);rn rs=ps.executeQuery();rn while (rs.next())rn rn //System.out.println(rs.getString("area_name"));rn System.out.println(rs.getString(2));//与上句一样rn rn rs.close();rn ps.close();rn rn catch (SQLException e)rn rn //System.out.println("SQLException:"+e.getMessage());rn System.out.println("SQL语句执行有误:"+e.getMessage());rn rn rnrn请各位指教,谢谢!rnrn 论坛

jsp通过jdbc 连接oracle数据库出现的问题?

11-23

大家帮我看一下我的这段连接数据库的 代码那里错了? rnrnrnrn rn rn <%@ page language = "java" import = "java.sql.*"%> rnrnrnrnrnrn <%rn tryrnrn DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());rnrn  rn//连结数据库,格式为(”jdbc:oracle:thin:@主机host:端口号:数据库名”,”用户名”,”密码”)rnConnection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:myora","sys","87409031");rnrn //创建SQL语句 rnrnStatement stmt=conn.createStatement();rnrn//处理查询结果rnrn ResultSet rset=stmt.executeQuery("select * from ding");rnrn while(rset.next())rnrn System.out.println(rset.getString(2));rn rn rset.close();rn stmt.close(); rn conn.close();rnrnSystem.out.println("linked ok"); rn catch(Exception e)rn out.println("SQLException:" + e);rn  rn%>rnrnrnrnrn错误提示;rnorg.apache.jasper.JasperException: Unable to compile class for JSPrnrnAn error occurred at line: 11 in the jsp file: /index1.jsprnrnGenerated servlet error:rn [javac] Compiling 1 source filernrnC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\index1_jsp.java:59: illegal character: \161rn?? rn^rnrnrnrnAn error occurred at line: 11 in the jsp file: /index1.jsprnrnGenerated servlet error:rnC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\index1_jsp.java:59: illegal character: \161rn?? rn ^rnrnrnrnAn error occurred at line: 11 in the jsp file: /index1.jsprnrnGenerated servlet error:rnC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\index1_jsp.java:82: illegal character: \161rn ??rn ^rnrnrnrnAn error occurred at line: 11 in the jsp file: /index1.jsprnrnGenerated servlet error:rnC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\index1_jsp.java:82: illegal character: \161rn ??rn ^rn4 errorsrnrnrn org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:83)rn org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:315)rn org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:406)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:463)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:442)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:430)rn org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:274)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:810)rn 论坛

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