Super_Scholar
你好,初始阶段学习,用jdbc即可。以下是比较通用的java连接mysql,参考下:public class DBUtil {Connection conn;PreparedStatement pstm;ResultSet rs; public DBUtil(){try {Properties properties = new Properties();InputStream is = DBUtil.class.getResourceAsStream("../../../jdbc.properties");properties.load(is);Class.forName(properties.getProperty("driver"));conn = DriverManager.getConnection(properties.getProperty("url"),properties.getProperty("uname"),properties.getProperty("upwd"));System.out.println("Ok~数据库成功连接!");} catch (Exception e) {System.out.println(e);}}//查public List find(String sql,Object...obj){Listlist = new ArrayList();try {pstm=conn.prepareStatement(sql);for (int i = 0; i < obj.length; i++) {pstm.setString(i+1, obj[i].toString());}rs = pstm.executeQuery();while(rs.next()){Mapmap= new HashedMap();ResultSetMetaData rsmd = (ResultSetMetaData) rs.getMetaData();for (int i = 0; i < rsmd.getColumnCount(); i++) {map.put(rsmd.getColumnName(i+1), rs.getString(i+1));}list.add(map);}} catch (SQLException e) {e.printStackTrace();System.out.println(e);}//System.out.println(list);return list;}//改public int cud(String cudSql,Object...obj){try {pstm=conn.prepareStatement(cudSql);for(int i=0; i0){System.out.println("添加成功");}else{System.out.println("添加失败");}}*/}