1
|
[root@localhost ~]# yum remove java-1.6.0-openjdk java-1.7.0-openjdk
|
편하게 아래 주소에서 받아도 된다. 받은 소스 파일을 압축을 풀고 적당한 곳에 옮겨준다
1
2
3
4
5
|
[root@localhost ~]# wget mirror.xinet.kr/java/jdk-8u191-linux-x64.tar.gz
[root@localhost ~]# tar xvfz jdk-8u191-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.8.0_191 /usr/local/java
|
1
2
3
4
5
6
7
|
[root@localhost ~]# vi /etc/profile
JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH="."
[root@localhost ~]# source /etc/profile
|
1
2
3
4
5
6
7
|
[root@localhost ~]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
[root@localhost ~]# javac -version
javac 1.8.0_191
|
mysql> create database xinet;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on xinet.* to xinet@localhost identified by 'xinet1234';
Query OK, 0 rows affected (0.00 sec)
mysql> use xinet;
Database changed
mysql> create table idol ( groupname varchar(50), membername varchar(50) );
Query OK, 0 rows affected (0.02 sec)
mysql> create table Users (id int(3) primary key, name varchar(20), email varchar(20), country varchar(20), password varchar(20));
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO Users (id, name, email, country, password) VALUES (1, 'Pankaj', 'pankaj@apple.com', 'India', 'pankaj123');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO Users (id, name, email, country, password) VALUES (4, 'David', 'david@gmail.com', 'USA', 'david123');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO Users (id, name, email, country, password) VALUES(5, 'Raman', 'raman@google.com', 'UK', 'raman123');
Query OK, 1 row affected (0.00 sec)
mysql> quit
jar 파일이 복사되는 경로는 /usr/local/java/jre/lib/ext/ 해당 경로에 복사해 주면 된다
1
2
3
|
[root@xinet ~]# wget https://downloads.mariadb.com/Connectors/java/connector-java-2.5.2/mariadb-java-client-2.5.2.jar
[root@xinet ~]# cp -a mariadb-java-client-2.5.2.jar /usr/local/java/jre/lib/ext/
|
[root@localhost java]# vi MySQLConn1.java
import java.sql.*;
public class MySQLConn1 {
static final String JDBC_DRIVER = "org.mariadb.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/xinet";
static final String USERNAME = "xinet";
static final String PASSWORD = "xinet1234";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,USERNAME,PASSWORD);
System.out.println("\n- MySQL Connection");
stmt = conn.createStatement();
String sql;
sql = "SELECT * FROM Users";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
String name = rs.getString("name");
String email = rs.getString("email");
String country = rs.getString("country");
System.out.print("\n** Name : " + name);
System.out.print("\n** Email : " + email);
System.out.print("\n -> Country: " + country);
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException se1){
se1.printStackTrace();
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}
}
System.out.println("\n\n- MySQL Connection Close");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@localhost ~]# javac MySQLConn1.java
[root@localhost ~]# java MySQLConn1
- MySQL Connection
** Name : Pankaj
** Email : pankaj@apple.com
-> Country: India
** Name : David
** Email : david@gmail.com
-> Country: USA
** Name : Raman
** Email : raman@google.com
-> Country: UK
- MySQL Connection Close
|
깃허브 VScode 연동 해서 사용하기 (0) | 2022.03.29 |
---|---|
Headers and client library minor version mismatch. (0) | 2022.01.10 |
linux centos7 한글깨짐 (0) | 2022.01.04 |
input type="text" readonly/disabled (0) | 2021.12.14 |
textarea 입력한 한/영 byte 자르기 (0) | 2021.11.19 |
댓글 영역