主方法 *** 作数据库【简单版】
public class JDBCDemo { private static final String DATAbase_DRIVER = "com.mysql.jdbc.Driver" ;//Oracle为oracle.jdbc.driver.OracleDriver private static final String DATAbase_URL = "jdbc:mysql://192.168.56.10:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai" ; private static final String DATAbase_USER = "root" ; private static final String DATAbase_PASSWORD = "root" ; public static void main(String[] args) throws Exception{ Class.forName(DATAbase_DRIVER); Connection connection = DriverManager.getConnection(DATAbase_URL,DATAbase_USER,DATAbase_PASSWORD); String sql = "INSERT INTO user(id,name,age,email) VALUES (?,?,?,?)"; PreparedStatement pstmt = connection.prepareStatement(sql); pstmt.setInt(1,1); pstmt.setString(2,"张三"); pstmt.setInt(3,18); pstmt.setString(4, UUID.randomUUID()+"@qq.com"); System.out.println(pstmt.execute()); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)