JDBC连接数据库
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Jdbc {
public static void main(String[] args) throws Exception {
String url = "jdbc:mysql://localhost:3306/bank";
String username = "root";
String password = "123456";
Connection conn = DriverManager.getConnection(url,username,password);
String sql = "update stu set id = 1 where name = '马运'";
Statement stmt = conn.createStatement();
int count = stmt.executeUpdate(sql);
System.out.println(count);
stmt.close();
conn.close();
}
}
我出错的地方,一个是把表的名字写到了数据库该写的地方,还有就是SQL语句的正确使用