ここからjdbc connector test本番
https://wiki.archlinux.org/index.php/JDBC_and_MySQL
こちらを参考にいたしました
rootでチェック
database emotherearthを事前につくっておく必要あり
create database emotherearth; grant all privileges on emotherearth.* to paulr@localhost identified by "paulr"; flush privileges;
自分家の環境にあわせて編集すること
[root@localhost ~]# cat DBDemo.java import java.sql.*; import java.util.Properties; public class DBDemo { // The JDBC Connector Class. private static final String dbClassName = "com.mysql.jdbc.Driver"; // Connection string. emotherearth is the database the program // is connecting to. You can include user and password after this // by adding (say) ?user=paulr&password=paulr. Not recommended! private static final String CONNECTION = "jdbc:mysql://127.0.0.1/emotherearth"; public static void main(String[] args) throws ClassNotFoundException,SQLException { System.out.println(dbClassName); // Class.forName(xxx) loads the jdbc classes and // creates a drivermanager class factory Class.forName(dbClassName); // Properties for user and password. Here the user and password are both 'paulr' Properties p = new Properties(); p.put("user","root"); p.put("password","xxxxxxxx"); // Now try to connect Connection c = DriverManager.getConnection(CONNECTION,p); System.out.println("It works !"); c.close(); } } [root@localhost ~]# [root@localhost ~]# java DBDemo com.mysql.jdbc.Driver It works ! [root@localhost ~]#