windows:
1 . dowload JDK1.7
2 解压缩到F:\jdk1.7
3 设置环境变量 PATH=F:\jdk1.7\bin;CLASSPATH=.;F:\jdk1.7\lib\tools.jar;F:\jdk1.7\lib\dt.jar; F:\oracle\product\10.2.0\db_1\jdbc\lib\classes12.jar
划红线的代表用jdbc与oracle连接的jar包
4 测试
java -version ---看JDK版本
5 HellWorld.java
javac C:\helloWorld.java
java HelloWorld
6 连接数据库的测试
C:\OraclTest.java
CMD: javac c:\OraclTest.java
java OraclTest
1 . dowload JDK1.7
2 解压缩到F:\jdk1.7
3 设置环境变量 PATH=F:\jdk1.7\bin;CLASSPATH=.;F:\jdk1.7\lib\tools.jar;F:\jdk1.7\lib\dt.jar; F:\oracle\product\10.2.0\db_1\jdbc\lib\classes12.jar
划红线的代表用jdbc与oracle连接的jar包
4 测试
java -version ---看JDK版本
5 HellWorld.java
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
javac C:\helloWorld.java
java HelloWorld
6 连接数据库的测试
C:\OraclTest.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class OraclTest
{
public static void main(String[] args)
{
try
{
//oracle具体配置
Class.forName("oracle.jdbc.driver.OracleDriver");
//oracle IP地址+端口号/SID
String url = "jdbc:oracle:thin:@192.168.64.200:1521:zhou1";
Connection con = DriverManager.getConnection(url,"scott","oracle");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("select * from test");
while(rs.next())
{
System.out.println(rs.getString(1)+rs.getString(2));
}
rs.close();
stat.close();
con.close();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class OraclTest
{
public static void main(String[] args)
{
try
{
//oracle具体配置
Class.forName("oracle.jdbc.driver.OracleDriver");
//oracle IP地址+端口号/SID
String url = "jdbc:oracle:thin:@192.168.64.200:1521:zhou1";
Connection con = DriverManager.getConnection(url,"scott","oracle");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("select * from test");
while(rs.next())
{
System.out.println(rs.getString(1)+rs.getString(2));
}
rs.close();
stat.close();
con.close();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
CMD: javac c:\OraclTest.java
java OraclTest
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/184303/viewspace-701241/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/184303/viewspace-701241/