JAVA 数据库连接
package Test;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class Test2{
public static void main(String[] args) throws Exception{
// if (System.getProperty("os.name").equals("AIX") && System.getProperty("os.name").equals("aix")) {
// System.out.println("this is Linux");
//
// } else if (System.getProperty("os.name").equals("Windows XP")) {
// System.out.println("this is windows xp");
// }
//System.out.println("s:"+ConstantUtil.getSysPro());
String sql = "";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.123:1521:DBNAME","userName","PWD");
if(!con.isClosed())
System.out.println("CONNECTION OK !");
else
System.out.println("CONNECTION error !");
// Statement st = con.createStatement();
// st.execute(sql);
/*
PreparedStatement pst = con.prepareStatement(sql);
//pst.
//System.getProperty()
InitialContext ict = new InitialContext();
DataSource ds = (DataSource)ict.lookup("");
con =ds.getConnection();*/
}
}
页:
[1]