mysqlのテーブルは
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
mysql> show tables;
+----------------------+
| Tables_in_helloworld |
+----------------------+
| test |
+----------------------+
1 row in set (0.03 sec)
mysql> desc test;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| helloworld | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
1 row in set (0.03 sec)
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
こうなっていて
eclipseのコードは
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class MyQuery {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Connection conn = null;
String url = "jdbc:mysql://localhost/helloworld?useSSL=false&requireSSL=false";
String user = "root";
String password = "password";
String msg = "";
try {
// ドライバロード
Class.forName("com.mysql.cj.jdbc.Driver");
// MySQLに接続
conn = DriverManager.getConnection(url, user, password);
// ステートメント生成
Statement stmt = conn.createStatement();
// SQLを実行
String sqlStr = "SELECT * FROM test";
ResultSet rs = stmt.executeQuery(sqlStr);
// 結果行をループ
while(rs.next()){
// レコードの値
int Field = rs.getInt("Field");
//表示
System.out.println(Field);
}
// 接続を閉じる
rs.close();
stmt.close();
}catch (ClassNotFoundException e){
msg = "ドライバのロードに失敗しました";
System.out.println(msg);
e.printStackTrace();
}catch (Exception e){
msg = "ドライバのロードに失敗しました";
System.out.println(msg);
e.printStackTrace();
}
}
}
ーーーーーーーーーーーーーーーーーーーー
こうなっていて実行してもエラーも結果も何も表示されないのですが
理由がわかりませんだれか教えてください。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
Java 出席状況を表す文字列から...
-
javaのfor文が機能してないみた...
-
yyyymmddからyyyy/mm/d...
-
テキストファイルから空白行をよむ
-
csv出力について
-
InputStream.read()でタイムア...
-
ループ処理の際、最後だけ","を...
-
JSPやサーブレットでSystem.out...
-
System.err. printlnとSystem.o...
-
C言語のポインターに関する警告
-
ダブルクォーテーションのrepla...
-
hiddenの値が期待した値で取得...
-
SwingでJtableのヘッダ行が表示...
-
javaで質問です。 文字列2023/2...
-
ORA-01858: 数値を指定する箇所...
-
strcmp関数などでの複数の文字...
-
逆コンパイルの見方について(...
-
EXCEL VBA で、0から?1から?
-
変数を動的に利用するには?
-
Javaでカレントディレクトリを...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
yyyymmddからyyyy/mm/d...
-
csv出力について
-
equalsの逆
-
Javaの質問です。テキストファ...
-
InputStream.read()でタイムア...
-
Inputstreamについて
-
javaのfor文が機能してないみた...
-
テキストファイルにおいて任意...
-
Windowsでの標準入力の終了の仕方
-
Javaでデータに登録する度にID...
-
テキストファイルから空白行をよむ
-
Java int sum = 0は必要ですか?
-
以下のJAVAプログラムでご質問...
-
FileクラスのcanRead/canWrite...
-
拡張子の読み込み制限を設けた...
-
九九を横に表示する。
-
Class.forNameでエラーになる
-
ObjectInputStreamとStreamCorr...
-
戻り値を使用する呼出
-
JAVAでエラーがでる。
おすすめ情報