Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package test;
- import java.util.Scanner;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- *
- * @author Rafog
- */
- public class Test {
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String DB_URL = "jdbc:mysql://localhost/biodata";
- static final String USER = "root";
- static final String PASS = "";
- static Connection conn;
- static Statement stmt;
- static ResultSet rs;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- try{
- String input,inputdb;
- Scanner keyboard=new Scanner(System.in);
- Class.forName(JDBC_DRIVER);
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
- System.out.println("silahkan Masukkan Pilihan:");
- System.out.println("1.Masukkan Data");
- System.out.println("2.Tampilkan Data");
- input=keyboard.next();
- if(input.equals("1"))
- {
- System.out.println("Anda telah Memilih 1");
- System.out.print("Masukkan sesuatu:");
- inputdb=keyboard.next();
- stmt=conn.createStatement();
- String sql="Insert into bio values('"+inputdb+"')";
- System.out.print("Sukses Menginput data");
- }
- else if(input.equals("2"))
- {
- System.out.println("Anda telah Memilih 2");
- stmt = conn.createStatement();
- String sql = "SELECT * FROM bio";
- rs=stmt.executeQuery(sql);
- while(rs.next()){
- System.out.println("Nama: " + rs.getString("nama"));
- }
- }
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement