zoukankan      html  css  js  c++  java
  • java jdbc数据库操作

     1 package shb.java.demo3;
     2 
     3 import java.sql.DriverManager;
     4 import java.sql.ResultSet;
     5 import java.sql.SQLException;
     6 import java.sql.Statement;
     7 /**
     8  * jdbc操作数据库
     9  * @Package:com.cnpc.dlp.web.event.controller
    10  * @Description:
    11  * @author Shihaobin
    12  * @Date 2015-8-27下午1:31:15
    13  */
    14 public class Demo12 {
    15     public static void main(String[] args) {
    16         String url = "jdbc:mysql://localhost:3306/base";
    17         String username = "root";
    18         String password = "bin";
    19         try {
    20             //加载数据库驱动
    21             Class.forName("com.mysql.jdbc.Driver");
    22         } catch (ClassNotFoundException e) {
    23             // TODO Auto-generated catch block
    24             e.printStackTrace();
    25         }
    26         try {
    27             //获得和数据库连接
    28             java.sql.Connection connection= DriverManager.getConnection(url, username, password);
    29             //创建查询对象
    30             Statement statement = connection.createStatement();
    31             String sqlinsert = "insert into usertable (username,password)values('lizhe','923840298')";
    32             String sqlString = "select username from usertable u where u.password = 'sdf'";
    33             //执行sql语句
    34             statement.execute(sqlinsert);
    35             System.out.println("success");    
    36             statement.close();
    37             connection.close();
    38         } catch (SQLException e) {
    39             // TODO Auto-generated catch block
    40             e.printStackTrace();
    41         } 
    42         
    43     }
    44 }

    如有错误请各位纠正,谢谢。

    吾宁做一叶扁舟,始航于湖边,遨游于海上,浪迹于江中。
  • 相关阅读:
    WCF自定义消息编码器 part 2 from MSDN
    EYQiPa,梦开始的地方
    WCF负载平衡 from MSDN
    WCF安全体系结构 from MSDN
    Introduction to Locking in SQL Server z
    WCF 性能计数器 from MSDN
    关于EYQiPa 持续更新
    12 个免费在线的 Web 网站性能测试工具 转
    使用FileSystemWatcher监控目录 z
    IIS相关
  • 原文地址:https://www.cnblogs.com/assassin666/p/4763050.html
Copyright © 2011-2022 走看看