Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class Tester {
- // field that we need
- private static Connection db;
- private static PreparedStatement stmt;
- // connection
- final static String URL = "jdbc:mysql://localhost:3106/";
- final static String DB_NAME = "evgany";
- final static String USER_NAME = "root";
- final static String USER_PASS = "";
- public static void main(String[] args) throws Exception {
- //creating our connectiuon string
- db = DriverManager.getConnection(URL+DB_NAME, USER_NAME, USER_PASS);
- //create a table for the first time, and if the table exists do not create it...
- createTable();
- }
- public static void createTable()
- {
- String sql="CREATE TABLE IF NOT EXISTS WEED (id INT PRIMARY KEY AUTO_INCReMeNT, name VARCHAR(16) NOT NULL, qty int(2)";
- try{
- //prepare statment for given SQL
- stmt = db.prepareStatement(sql);
- //execure the fucking statment
- stmt.execute();
- }
- catch (SQLException e){
- e.printStackTrace();
- }
- System.out.println("Table was created.......");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement