package jdbcexampleproject;
import java.sql.*;
public class AccessDbUtil
{
public static void AccessDb()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@f7e1bd176bae426:1521:touming","scott","tiger");
// Statement state=conn.createStatement();
// int r=state.executeUpdate("insert into emp(EMPNO,ENAME) values('2222','handan')");
// ResultSet rs= state.executeQuery("select * from emp");
PreparedStatement state=conn.prepareStatement("select * from emp where ENAME=?");
state.setString(1,"handan");
ResultSet rs= state.executeQuery();
while(rs.next())
{
System.out.print(rs.getString(1)+" ");
System.out.print(rs.getString(2)+" ");
System.out.print(rs.getString(3)+" ");
System.out.print(rs.getString(4)+" ");
System.out.print(rs.getString(5)+" ");
System.out.print(rs.getString(6)+" ");
System.out.print(rs.getString(7)+" ");
System.out.println(rs.getString(8));
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String []args)
{
AccessDb();
}
}
[转]数据库操作-程序-java--oracle
最新推荐文章于 2023-12-19 09:07:04 发布