Skip to content

Instantly share code, notes, and snippets.

@goyuninfo
Last active August 29, 2015 14:01
Show Gist options
  • Save goyuninfo/c5cfe72139be037ff9ba to your computer and use it in GitHub Desktop.
Save goyuninfo/c5cfe72139be037ff9ba to your computer and use it in GitHub Desktop.
package com.mycompany.mavenproject3;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author i88ca
*/
public class NewClass {
public static void main(String args[]) throws SQLException {
final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
final String DB_URL = "jdbc:mysql://192.168.1.191:3306/transit?zeroDateTimeBehavior=convertToNull";
// Database credentials
final String USER = "user";
final String PASS = "pass";
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DB_URL, USER, PASS);
preparedStatement = connection.prepareStatement("select * from sun.contest_upload");
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
System.out.println(resultSet.getString("listid"));
}
} catch (ClassNotFoundException | SQLException classNotFoundException) {
} finally {
if (preparedStatement != null) {
preparedStatement.close();
}
if (connection != null) {
connection.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment