java中连接Oracle数据源

java中连接Oracle数据源
本地不安装Oracle,用JAVA实现连接Oracle数据源:
数据库服务器:lips-db        端口: 1521         数据库名:JAVATECH
连接用户名:ebt        连接密码:ebt06        
import  java.sql. * ;
/** */ /**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * 
@author not attributable
 * 
@version 1.0
 
*/

public   class  Welcome  {

    
public static Connection getConnect() throws SQLException
    
{
        DriverManager.registerDriver(
new oracle.jdbc.OracleDriver());
        Connection conn 
= DriverManager.getConnection(
            
"jdbc:oracle:thin:@lips-db:1521:javatech""ebt""ebt06");
        
return conn;
    }


    
public static void main(String[] args) {
        
try {
            Connection conn 
= Welcome.getConnect();
            Statement stmt 
= conn.createStatement();
            ResultSet rs 
= stmt.executeQuery("select * from tbm_student");

            ResultSetMetaData rsmd 
= rs.getMetaData();
            
for (int i = 1, n = rsmd.getColumnCount(); i <= n; i++)
            
{
                System.out.print(rsmd.getColumnName(i));
                System.out.print(
",");
                System.out.print(rsmd.getColumnClassName(i));
                System.out.print(
",");
                System.out.print(rsmd.getColumnTypeName(i));
                System.out.println(
"");
            }

        }

        
catch (SQLException se) {
            
//
        }

        
catch (Exception ex) {
            
//
        }

    }

}

要成功运行,还需要引入classesxx.jar或者classesxx.zip:
<? xml version="1.0" encoding="UTF-8" ?>
< classpath >
    
< classpathentry  kind ="src"  path ="" />
    
< classpathentry  kind ="con"  path ="org.eclipse.jdt.launching.JRE_CONTAINER" />
    
<classpathentry kind="lib" path="C:/oracle/ora92/jdbc/lib/classes12.jar"/>
    
< classpathentry  kind ="output"  path ="" />
</ classpath >

你可能感兴趣的:(java中连接Oracle数据源)