Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.aviadhemo;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- public class Main {
- public static String driver = "org.gjt.mm.mysql.Driver";
- public static String protocol = "jdbc:mysql://localhost:3306/gagamo";
- public static String user = "aviadh";
- public static String password = "200135594";
- public static void main(String[] args)
- {
- Connection connection = null;
- Statement statement = null;
- ResultSet resultSet = null;
- try
- {
- connection = null;
- Class.forName(driver);
- connection = DriverManager.getConnection(protocol, user, password);
- statement = connection.createStatement();
- statement.execute("create table inventory(id int, fee double)");
- statement.execute("insert into inventory values (100212,2.5)");
- statement.execute("insert into inventory values (100213,1.2)");
- statement.execute("insert into inventory values (100214,4.2)");
- resultSet = statement.executeQuery(
- "SELECT id, fee FROM inventory ORDER BY id");
- while(resultSet.next()){
- System.out.println("id=" + resultSet.getInt("id") + " fee=" + resultSet.getDouble("fee"));
- }
- statement.execute("DROP TABLE inventory");
- }
- catch(Exception e){
- e.printStackTrace();
- }
- finally{
- if(statement!=null) try{statement.close();}catch(Exception e){}
- if(connection!=null) try{connection.close();}catch(Exception e){}
- if(resultSet != null) try{resultSet.close();}catch(Exception e){}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement