String driver = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://127.0.0.1:3306/phpdb";
		String u = "root";
		String p = "sa123456";
		
		try {
			Class.forName(driver);
			Connection con = DriverManager.getConnection(url,u,p);
			if(!con.isClosed()){
				System.out.println("链接成功...");
				Statement statement = con.createStatement();
				String sql = "select * from articles";
				String insertSql = "insert into articles(title,content) values(?,?)";
				//执行查询操作
				ResultSet rs = statement.executeQuery(sql);
				
				PreparedStatement ps = con.prepareStatement(insertSql);
				ps.setString(1, "哈哈哈1111");
				ps.setString(2, "写入数据成功啦....");
				//执行增、删、改操作
				ps.executeUpdate();
				
				while(rs.next()){
					System.out.println(rs.getString("content"));
				}
				rs.close();
				con.close();
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

 

 

相关文章:

  • 2022-12-23
  • 2019-03-10
  • 2021-08-06
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-11-28
  • 2022-01-31
  • 2022-01-31
  • 2021-12-10
  • 2022-12-23
  • 2021-12-04
相关资源
相似解决方案