1. Trang chủ
  2. » Thể loại khác

Java - Trang ď JDBC

10 129 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 150,11 KB

Nội dung

Java Programming How to Use Java DataBase Connectivities (JDBC) Incheon Paik Java Computer Industry Lab Contents „ „ „ „ „ Java Simple SQL Creating Table Insert Data Select Data Accessing Data Using JDBC Computer Industry Lab Simple Database Design student studentID Name Email major course registration call_number name teacher semester SID call_num Java Computer Industry Lab Database Table Creation SQL Statement CREATE TABLE student ( studentID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30) NOT NULL, email VARCHAR(45), major VARCHAR(15) ); CREATE TABLE course ( call_number INT NOT NULL PRIMARY KEY, name VARCHAR(25) NOT NULL, teacher VARCHAR(30), semester VARCHAR(10) NOT NULL ); CREATE TABLE registration ( SID INT NOT NULL, call_num INT NOT NULL, PRIMARY KEY (SID, call_num) ); Java Computer Industry Lab Database Table Creation (Running Screen) Java Computer Industry Lab Table Structure Java Computer Industry Lab Insert & Select Data Java Computer Industry Lab Select Data Java Computer Industry Lab Use JDBC import java.sql.*; import java.io.*; // This example is running with MySql public class MyTest{ public static void main(String[] args){ String url = "jdbc:mysql://localhost/paikic?useUnicode=true&characterEncoding=EUC_JP"; String query = "select * from course"; Connection myCon = null; Statement stmt = null; try{ Class.forName("org.gjt.mm.mysql.Driver"); }catch(ClassNotFoundException e){ System.err.println("Class Load Error"); System.err.println(e.getMessage()); } try{ System.out.println("Trying to connect "); myCon = DriverManager.getConnection(url,"root", "sccp2002"); stmt = myCon.createStatement(); ResultSet rs = stmt.executeQuery(query); while(rs.next()){ String col1 = rs.getString(1); String col2 = rs.getString(2); String col3 = rs.getString(3); String col4 = rs.getString(4); System.out.println(" " + col1 + " : " + col2 + " : " + col3 + " : " + col4); } Java } } rs.close(); stmt.close(); myCon.close(); } catch(SQLException e){ System.out.println("MY" + url+" : "); System.err.println(e.getMessage()+e.toString()); } Computer Industry Lab Use JDBC (Running Screen) Java 10 Computer Industry Lab ... Data Java Computer Industry Lab Use JDBC import java. sql.*; import java. io.*; // This example is running with MySql public class MyTest{ public static void main(String[] args){ String url = "jdbc: mysql://localhost/paikic?useUnicode=true&characterEncoding=EUC_JP";... (SID, call_num) ); Java Computer Industry Lab Database Table Creation (Running Screen) Java Computer Industry Lab Table Structure Java Computer Industry Lab Insert & Select Data Java Computer Industry...Contents „ „ „ „ „ Java Simple SQL Creating Table Insert Data Select Data Accessing Data Using JDBC Computer Industry Lab Simple Database Design student

Ngày đăng: 09/12/2017, 02:05

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN