简单连接并插入一天信息进入oracle数据库
1.[代码][Java]代码
import java.sql.*;
public class ZipCompress {
private static String URL = "jdbc:oracle:thin:@10.128.50.23:1521:orcl";
private static String ID = "optixcms";
private static String PD = "optixcms";
public static Connection conn;
public static PreparedStatement ps;
public static ResultSet rs;
public static Statement st;
public void getConnection(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn= DriverManager.getConnection(URL, ID, PD);
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String args[]){
ZipCompress zc= new ZipCompress();
zc.getConnection();
if(conn == null)
{
System.out.println("与数据库链接失败!");
}
else
{
System.out.println("与数据库链接成功");
}
try{
String sql = "insert into TEST(id,name) values(2,'wx')";
st= (Statement)conn.createStatement();
int count=st.executeUpdate(sql);
System.out.println("向数据库test插入" + count + "条数据");
}catch(SQLException e){
System.out.println("插入数据失败"+e.getMessage());
}
}
}