如何在没有matlabs数据库工具箱的情况下从matlab访问postgresql数据库?

前端之家收集整理的这篇文章主要介绍了如何在没有matlabs数据库工具箱的情况下从matlab访问postgresql数据库?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试使用 pgmex.不幸的是它不适用于libpq5(matlab立即崩溃).

解决方法

要在没有数据库工具箱的情况下从matlab连接到postgres,请执行以下操作:
  1. % Add jar file to classpath (ensure it is present in your current dir)
  2. javaclasspath('postgresql-9.0-801.jdbc4.jar');
  3.  
  4. % Username and password you chose when installing postgres
  5. props=java.util.Properties;
  6. props.setProperty('user','<your_postgres_username>');
  7. props.setProperty('password','<your_postgres_password>');
  8.  
  9. % Create the database connection (port 5432 is the default postgres chooses
  10. % on installation)
  11. driver=org.postgresql.Driver;
  12. url = 'jdbc:postgresql://<yourhost>:<yourport>\<yourdb>';
  13. conn=driver.connect(url,props);
  14.  
  15. % A test query
  16. sql='select * from <table>'; % Gets all records
  17. ps=conn.prepareStatement(sql);
  18. rs=ps.executeQuery();
  19.  
  20. % Read the results into an array of result structs
  21. count=0;
  22. result=struct;
  23. while rs.next()
  24. count=count+1;
  25. result(count).var1=char(rs.getString(2));
  26. result(count).var2=char(rs.getString(3));
  27. ...
  28. end

猜你在找的MsSQL相关文章