常用数据库连接语句
一:Mysql的数据库连接语句
   
Class.forName("sql.jdbc.Driver");
    Connection con = Connection.("jdbc:mysql://localhost:3306/bookinfo","root","123");
    Statement st = ateStatement();
    String sql = "select * from book";
    ResultSet rs = st.executeQuery(sql);
      ()){
    }

二:sqlserver的数据库连接语句

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    Connection con = Connection.("jdbc:microsoft:sqlserver://localhost:1433;databaseName=bookinfo","sa","123");
 
 
  PreparedStatement ps = con.prepareStatement("select * from book");
  ResultSet rs = ps.executeQuery();
 
()){
  out.String(2));
 
  } jdbc连接oracle


三:sqlserver2005的数据库连接语句
   
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con = Connection.("jdbc:sqlserver://localhost:1433;databaseName=bookinfo","sa","123");
 
 
  PreparedStatement ps = con.prepareStatement("select * from book");
 
 
  ResultSet rs = ps.executeQuery();
 
 
  ()){
 
  out.String(2));
 
  }


四:oracle的数据库连接语句

jdbc:oracle:thin:@<server>[:<1521>]:<database_name>
Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = Connection.("jdbc:oracle:thin:@localhost:1521:bookinfo","zhangsan","123");
 
 
  PreparedStatement ps = con.prepareStatement("select * from book");
 
 
  ResultSet rs = ps.executeQuery();
 
 
  ()){
 
  out.String(2));
 
  }

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。