eclipse 执行mysql语句_关于Oracle的在Eclipse中操作的命令语句

Connection con=this.creatCon();//获得连接 PreparedStatement pstm=null;//命令器String sql=quot;insert into student(stu

Connection con=this.creatCon();//获得连接

PreparedStatement pstm=null;//命令器

String sql="insert into student(student_id,name,sex,age) values(?,?,?,?)";//设置要执行的SQL语句

pstm=con.prepareStatement(sql);//准备执行SQL语句命令

pstm.setString(2, name);//设置第2个问号的值

pstm.setString(3, sex);//设置第3个问号的值

pstm.setInt(4, age);//设置第4个问号的值

pstm.setInt(1,student_id);//设置第1个问号的值

//pstm.executeQuery();//执行SQL命令,这个命令是在查询的时候,返回数据集ResultSet

pstm.executeUpdate();//执行SQL命令,当是插入,,删除,修改的时候用

System.out.println("写入成功");//执行后写出是否成功

连接的打开和关闭:

// 创建一个连接Oracle数据库的类

public static Connection creatCon()

{

String username="scott";

String password="tiger";

Connection con=null;

try

{

Class.forName("oracle.jdbc.driver.OracleDriver");

String url="java:oracle:thin:@localhost:1521:ora9i";//连接Oracle数据库

/*class.forName("com.micrsoft.jdbc.sqlserver.SQLServerDriver");

String url="java:microsoft:sqlserver://localhost:1433";//连接SQL server数据库*/

con=(Connection)DriverManager.getConnection(url,username,password);

return con;

}

catch(Exception exc)

{

System.out.println(exc);

}

return null;

}

//关闭连接

public void closeCon(Connection c)

{

try

{

c.close();

}

catch(Exception c1)

{

System.out.println(c1);

}

}

logo.gif

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值