Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package jdbcukol;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Random;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- class Ukol1
- {
- Connection con;
- public Ukol1() {
- con = getConnection();
- Statement stm;
- try {
- stm = con.createStatement();
- ResultSet rs = stm.executeQuery("select * from products");
- Random rand = new Random();
- int num = rand.nextInt(50);
- rs.absolute(num);
- rs.next();
- int x = rs.getInt("products_quantity");
- System.out.println(num + ". " + x);
- x += 100;
- stm.execute("UPDATE PRODUCTS SET PRODUCTS_QUANTITY=" + x + " WHERE products_id=" + num);
- ResultSet rs2 = stm.executeQuery("select * from products");
- rs2.absolute(num);
- rs2.next();
- x = rs2.getInt("products_quantity");
- System.out.println(num + ". " + x);
- con.close();
- } catch (SQLException ex) {
- Logger.getLogger(Ukol1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static Connection getConnection(){
- Connection con = null;
- try {
- con = DriverManager.getConnection(
- "jdbc:mysql://pca1035a.vsb.cz/shop", "shop", "shop");
- } catch (SQLException e) {
- }
- return con;
- }
- }
- /**
- *
- * @author tomas
- */
- public class JDBCukol {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- try {
- // TODO code application logic here
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(JDBCukol.class.getName()).log(Level.SEVERE, null, ex);
- }
- Ukol1 u1 = new Ukol1();
- }
- }
Add Comment
Please, Sign In to add comment