java JDBC (三) 修改

package cn.sasa.demo3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner; public class JDBCDemo3 { public static void main(String[] args) throws ClassNotFoundException, SQLException {
double price = 0;
int pid = 0;
Scanner sc = new Scanner(System.in);
System.out.println("price");
price = sc.nextDouble();
System.out.println("pid");
pid = sc.nextInt();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.0.207:3306/mydb", "root", "XXXXXXXXXXXXXX1"); String sql = "UPDATE product SET price=? WHERE pid=?;";
PreparedStatement pstate = conn.prepareStatement(sql);
pstate.setObject(1, price);
pstate.setObject(2, pid);
int rows = pstate.executeUpdate();
System.out.println(rows); pstate.close();
conn.close();
} }
上一篇:redhat7.3安装python3 pip3


下一篇:python爬虫:使用 BeautifulSoup+正则表达式 提取数据