oracle 连接数据库及ojdbc包

package com.shine.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCExample {

/**
* @param args
*/
public static void main(String[] args) {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@10.168.2.230:1521:shine";
String username = "system";
String password = "oracle";
String sql = "insert into users(username,password) values(?,?)";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, "abc");
ps.setString(2, "123");
ps.executeUpdate();
ps.close();
conn.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

你可能感兴趣的:(java,oracle,sql,jdbc)