日期:2014-05-18 浏览次数:20798 次
public static void main(String[] args) { Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:tct108", "site_test", "..."); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { if (conn != null) try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
------解决方案--------------------
public class dbmanger { private String driver="oracle.jdbc.driver.OracleDriver"; private String user="site_test "; private String password=""; private String url="jdbc:oraclethin:@MyDbComputerNameOrIP/tct108"; private Connection con=null; public dbmanger() { try { Class.forName(driver); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { con=DriverManager.getConnection(url, user, password); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public Connection getConnection() { if(con==null) { try { con=DriverManager.getConnection(url,user,password); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return con; } public void close(){ if(con!=null) { try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
------解决方案--------------------
------解决方案--------------------
把本地硬盘里的图片存储到oracle数据库里blob的实现
------解决方案--------------------
上面朋友的做法都可以的
呵呵,建议楼主对基本的数据库连接方法要熟练使用
------解决方案--------------------
public static void main(String[] args) {
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:tct108", "site_test",
"...&qu