ITPub博客

首页 > 数据库 > 数据库开发技术 > 数据库编程方法总结

数据库编程方法总结

原创 数据库开发技术 作者:junnyblog 时间:2009-10-25 23:46:42 0 删除 编辑

针对现在很多应用都与数据库通信相关.讲诉常用的数据库编程方法.如:通用的ODBC,JDBC.或者针对某一类型数据库编程方法进行总结.整理时间:2009-12-01至2009-12-31

[@more@]

package com.sp;

import java.sql.*;

public class TestOra {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection ct=null;
Statement sm=null;
ResultSet rs=null;
try {
//jdbc-odbc
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Connection ct=DriverManager.getConnection("jdbc:odbc:wgods","scott","tiger");
// Statement sm=ct.createStatement();
//
// ResultSet rs=sm.executeQuery("select * from emp");


//jdbc mysql
//Class.forName("com.mysql.jdbc.Driver");
//ct=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/wgods?user=root&password=");


//jdbc
Class.forName("oracle.jdbc.driver.OracleDriver");
ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:wgods","scott","tiger");
sm=ct.createStatement();
rs=sm.executeQuery("select * from emp");
while(rs.next())
{
System.out.println("用户名:"+rs.getString(2));
}

} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
} finally
{
try {
rs.close();
sm.close();
ct.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22630256/viewspace-1028130/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 系统之间差异
请登录后发表评论 登录
全部评论

注册时间:2009-09-30

  • 博文量
    58
  • 访问量
    612588