Created
March 21, 2018 15:34
-
-
Save mc256/ab9647ca283ac087dfd1776c0c619345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.sql.*; | |
public class TestMysql { | |
public static void main(String[] args) { | |
try { | |
Class.forName("com.mysql.jdbc.Driver"); | |
Connection cnt = DriverManager.getConnection("jdbc:mysql://localhost/app_server", "app_server", "WVezBsbqNPCSMMyN"); | |
// Method 1 | |
Statement stm = cnt.createStatement(); | |
ResultSet rss = stm.executeQuery("SELECT * FROM `kashima_bangumi`"); | |
while (rss.next()) { | |
System.out.printf("%s %s %d\n", rss.getString("btitlecn"), rss.getString("btitlejp"), rss.getInt("bwa")); | |
} | |
// Method 2 | |
PreparedStatement pstm = cnt.prepareStatement("SELECT `bid`, `btitlecn`, `btitlejp`, `bwa` FROM `kashima_bangumi` WHERE `btitlecn` like ? OR `btitlejp` like ? LIMIT ?, 10;"); | |
pstm.setString(1, "%锟斤拷%"); | |
pstm.setString(2, "%锟斤拷%"); | |
pstm.setInt(3, 0); | |
// pstm.executeUpdate();// 没锟叫凤拷锟斤拷值 | |
rss = pstm.executeQuery(); | |
while (rss.next()) { | |
System.out.printf("%s %s %d\n", rss.getString("btitlecn"), rss.getString("btitlejp"), rss.getInt("bwa")); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment