⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testjdbc.java

📁 电子通讯录实现网上保存朋友
💻 JAVA
字号:
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.logging.Level;import java.util.logging.Logger;/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author Jason */public class TestJDBC {    public static void main(String[] args) {        try {            //1.            Class.forName("com.mysql.jdbc.Driver");            //2.            Connection con = DriverManager.getConnection(                    "jdbc:mysql://localhost:3306/eabook","root","root");            //3.            Statement statement = con.createStatement();            //4.            //add//            String sql = "insert into t_record_type (typename) values('同学')";//            int result = statement.executeUpdate(sql);//          //update//            String sql = "update t_record_type set typename = '同事' where typeid = 3";//            int result = statement.executeUpdate(sql);            //delete//            String sql = "delete from t_record_type where typeid = 3";//            int result = statement.executeUpdate(sql);//            if(result == 1){//                System.out.println("add success");//                  System.out.println("update success");//                System.out.println("delete success");//            }            //query            String sql = "select * from t_record_type";            ResultSet rs = statement.executeQuery(sql);            while(rs.next()){                System.out.println("编号:" + rs.getInt("typeid"));                System.out.println("记录类型:" + rs.getString("typename"));                System.out.println("******************************");            }            if(statement != null){                statement.close();            }            if(con != null){                System.out.println("OK");                con.close();            }        } catch (SQLException ex) {            Logger.getLogger(TestJDBC.class.getName()).log(Level.SEVERE, null, ex);        } catch (ClassNotFoundException ex) {            Logger.getLogger(TestJDBC.class.getName()).log(Level.SEVERE, null, ex);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -