当前位置导航:炫浪网>>网络学院>>网页制作>>JSP教程

java连接Oracle数据库

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());
}
}
}
}


相关内容
赞助商链接