Java 连接Oracle
需要把oracle/common/lib/classes12.zip 复制到工程的lib中。
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class test {
/\*\*
\* @param args
\*/
public static void main(String\[\] args) \{
// TODO Auto-generated method stub
// System.out.print(“hello”);
// InputStream a = (test.class).getResourceAsStream(“messages_ja.properties”);
Connection conn= getConnection();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select \* from et\_boshyoujiinfo");
\} catch (SQLException e) \{
// TODO Auto-generated catch block
e.printStackTrace();
\}
\}
public static Connection getConnection()
\{
Connection con = null;
String url = "jdbc:oracle:thin:@192.168.1.2:1521:ORCL";
String userName ="scott";
String password ="tiger";
String driver="oracle.jdbc.driver.OracleDriver";
try
\{
Class.forName(driver);
con = DriverManager.getConnection(url, userName, password);
\}
catch(SQLException e)
\{
e.printStackTrace();
\}
catch(ClassNotFoundException ex)
\{
ex.printStackTrace();
\}
return con;
\}
}
还没有评论,来说两句吧...