User Tools

Site Tools


classes:general:dbsamples:java_mysql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
classes:general:dbsamples:java_mysql [2020/10/26 12:22] – created localadminclasses:general:dbsamples:java_mysql [2020/11/02 09:03] (current) localadmin
Line 1: Line 1:
 +For Java database connections you will need to add the proper JDBC library to your project or classpath.
 +
 +<code>
 import java.sql.Connection; import java.sql.Connection;
 import java.sql.DriverManager; import java.sql.DriverManager;
Line 11: Line 14:
     public static void main(String[] args) {     public static void main(String[] args) {
  
-        String url = "jdbc:mysql://rei.cs.ndsu.nodak.edu:3306/olympiad?useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"; +        // Configure jdbc connection string properties as necessary for your setup. 
-        String user = "olympiad"; +        String url = "jdbc:mysql://host.cs.ndsu.nodak.edu:3306/dbname?useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"; 
-        String password = "B6pLyr49";+        String user = "remoteUser"; 
 +        String password = "bigsecurepassword";
  
-        String query = "SELECT event_date FROM so15_tournament WHERE active=FALSE";+        String query = "SELECT table_name.column_name 
 +                        FROM table_name 
 +                        WHERE table_name.field=something";
  
-        try (Connection con = DriverManager.getConnection(url, user, password); +        try (Connection conn = DriverManager.getConnection(url, user, password); 
-            Statement st = con.createStatement();+            Statement st = conn.createStatement();
             ResultSet rs = st.executeQuery(query)) {             ResultSet rs = st.executeQuery(query)) {
  
Line 33: Line 39:
     }     }
 } }
 +</code>
classes/general/dbsamples/java_mysql.1603732932.txt.gz · Last modified: 2020/10/26 12:22 by localadmin