java连接Oracle数据库
类别: JAVA教程
import java.net.URL;
import java.sql.*;
public class JavaOracle {
public JavaOracle() {
}
public static void main(String[] args){
try
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print(e.getMessage());
}
String url="jdbc:oracle:thin:@Server:1521:SDCDB";
Connection conn=DriverManager.getConnection(url,"test","test");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select score from MY");
while(rs.next())
{
System.out.println(rs.getString(1));
}
conn.close();
}
catch(SQLException ex)
{
while(ex!=null)
{System.out.println(ex.getSQLState());
}
}
}
}
import java.sql.*;
public class JavaOracle {
public JavaOracle() {
}
public static void main(String[] args){
try
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print(e.getMessage());
}
String url="jdbc:oracle:thin:@Server:1521:SDCDB";
Connection conn=DriverManager.getConnection(url,"test","test");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select score from MY");
while(rs.next())
{
System.out.println(rs.getString(1));
}
conn.close();
}
catch(SQLException ex)
{
while(ex!=null)
{System.out.println(ex.getSQLState());
}
}
}
}
- 上一篇: java文件操作大全
- 下一篇: java在Oracle中建表
-= 资 源 教 程 =-
文 章 搜 索