[AppleScript] 纯文本查看 复制代码
package cn.jdbcDemo;
import com.mysql.jdbc.Driver;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;
public class demo8 {
public static void main(String[] args) throws IOException {
Properties p = new Properties();
InputStream is = demo8.class.getClassLoader().getResourceAsStream("new.properties");
p.load(is);
String url = p.getProperty("url");
String user = p.getProperty("user");
String password = p.getProperty("password");
String driver = p.getProperty("driver");
Connection conn=null;
PreparedStatement pstmt=null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
String s ="UPDATE student set age =+'?'+"where id ="+'?';
pstmt = conn.prepareStatement(s);
pstmt.setInt(1,10);
pstmt.setInt(2,1);
int i = pstmt.executeUpdate(s);
System.out.println("执行了"+i+"行");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(conn!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
/*
369258147
*/
}
}