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数据库
系统功能强大、操作便捷并具有高度延续开发的内容与知识管理系统,并可集合系统强大的新闻、产品、下载、投票、人才、留言、在线订购、搜索引擎优化、等功能模块,为企业部门提供一个简单、易用、开放、可扩展的企业信息门户平台或电子商务运行平台。开发人员为脆弱页面专门设计了防刷新系统,自动阻止恶意访问和攻击;安全检查应用于每一处代码中,每个提交到系统查询语句中的变量都经过过滤,可自动屏蔽恶意攻击代码,从而全面防
0
/*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);
}
}

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号