Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*source: http://stackoverflow.com/questions/2451892/how-do-i-connect-to-a-sql-server-2008-database-in-java-with-jdbc*/
- import java.sql.*;
- import javax.sql.*;
- public class jdbcdemo{
- public static void main(String args[]){
- String dbtime;
- String dbUrl = "jdbc:mysql://your.database.domain/yourDBname";
- String dbClass = "com.mysql.jdbc.Driver";
- String query = "Select * FROM users";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection (dbUrl);
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- dbtime = rs.getString(1);
- System.out.println(dbtime);
- } //end while
- con.close();
- } //end try
- catch(ClassNotFoundException e) {
- e.printStackTrace();
- }
- catch(SQLException e) {
- e.printStackTrace();
- }
- } //end main
- } //end class
Advertisement
Add Comment
Please, Sign In to add comment