how to write queries in java
Java
2, Fred, Flinstone, 2010-06-23, false, 6000
3, Barney, Rubble, 2010-06-23, false, 5000
import java.sql.*;
/**
* A Java MySQL SELECT statement example.
* Demonstrates the use of a SQL SELECT statement against a
* MySQL database, called from a Java program.
*
* Created by Alvin Alexander, http://alvinalexander.com
*/
public class JavaMysqlSelectExample
{
public static void main(String[] args)
{
try
{
// create our mysql database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/test";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "");
// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
String query = "SELECT * FROM users";
// create the java statement
Statement st = conn.createStatement();
// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);
// iterate through the java resultset
while (rs.next())
{
int id = rs.getInt("id");
String firstName = rs.getString("first_name");
String lastName = rs.getString("last_name");
Date dateCreated = rs.getDate("date_created");
boolean isAdmin = rs.getBoolean("is_admin");
int numPoints = rs.getInt("num_points");
// print the results
System.out.format("%s, %s, %s, %s, %s, %s\n", id, firstName, lastName, dateCreated, isAdmin, numPoints);
}
st.close();
}
catch (Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
Also in Java:
- Title
- java sleep in code
- Category
- Java
- Title
- java fx display simple rectangle
- Category
- Java
- Title
- integer to string java
- Category
- Java
- Title
- java length of matrix
- Category
- Java
- Title
- spigot actionbar
- Category
- Java
- Title
- immagini java
- Category
- Java
- Title
- string method example in java
- Category
- Java
- Title
- pattern.compile java
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- has been compiled by a more recent version of the Java Runtime (class file version 56.0), this version of the Java Runtime only recognizes class file versions up to 55.0
- Category
- Java
- Title
- eliminar fila jtable java
- Category
- Java
- Title
- java rest client response json
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- how to write sensor data into file android studio
- Category
- Java
- Title
- esponente in java
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- array rotation program in java
- Category
- Java
- Title
- rock paper scissors java
- Category
- Java
- Title
- send variable intent
- Category
- Java
- Title
- select photo from camera android
- Category
- Java
- Title
- java program to display characters from a to z using loop
- Category
- Java
- Title
- get cursor position in textarea java
- Category
- Java
- Title
- java create directory
- Category
- Java
- Title
- java vs python
- Category
- Java
- Title
- how to replace in java
- Category
- Java
- Title
- java script to detect the crome browser
- Category
- Java
- Title
- resurce leak java
- Category
- Java
- Title
- creating array java
- Category
- Java
- Title
- java remove duplicates
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- initialiser une arraylist
- Category
- Java
- Title
- gradle require java version
- Category
- Java
- Title
- javafx action event enter key
- Category
- Java
- Title
- create instance object java
- Category
- Java
- Title
- nth prime number java
- Category
- Java
- Title
- how to exit a for loop in java
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- restart application programmatically android
- Category
- Java
- Title
- java - a program to print open ports
- Category
- Java
- Title
- get today date in java 8
- Category
- Java
- Title
- create notification android
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- in dom parser how to find processing instruction in java
- Category
- Java
- Title
- java script using navigator.useragent to detect the browse
- Category
- Java
- Title
- left shift in java
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- show menuitem when menu hovered javafx
- Category
- Java
- Title
- how to calculate exponential in java
- Category
- Java
- Title
- inheritance in java
- Category
- Java
- Title
- java manacher's algorithm
- Category
- Java
- Title
- casting java
- Category
- Java
- Title
- java boolean even number
- Category
- Java
- Title
- java put a char array into a string
- Category
- Java
- Title
- parallel sorting in java 8
- Category
- Java
- Title
- para que sirve getcontentpane en java
- Category
- Java
- Title
- binary string to int java
- Category
- Java
- Title
- string to arraylist convert java
- Category
- Java
- Title
- find the day of the week Calendar class in java
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- java simple jframe example
- Category
- Java
- Title
- java variable declaration
- Category
- Java
- Title
- how to return the first character in an array from a method java
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- java jagged array days and months
- Category
- Java
- Title
- set password visible in android
- Category
- Java
- Title
- java file class
- Category
- Java
- Title
- java null pointer exception
- Category
- Java
- Title
- java print treemap
- Category
- Java
- Title
- java 8 map foreach
- Category
- Java
- Title
- javafx textarea size
- Category
- Java
- Title
- how to add jar in maven java application in netbeans
- Category
- Java
- Title
- java read lines from file
- Category
- Java
- Title
- java android development find element by id
- Category
- Java
- Title
- java arraylist
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- center textview programmatically android
- Category
- Java
- Title
- java get current milliseconds
- Category
- Java
- Title
- java script dynamic varibale creation
- Category
- Java
- Title
- java check if string is number
- Category
- Java
- Title
- java resultset to table
- Category
- Java
- Title
- bootstrap alert
- Category
- Java
- Title
- change the value in a hashtable java
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- java loop hashmap
- Category
- Java
- Title
- print in one line in java
- Category
- Java
- Title
- butterfly pattern program in java
- Category
- Java
- Title
- is self divisor java
- Category
- Java
- Title
- fibonacci sequence in java recursion
- Category
- Java
- Title
- islowercase java
- Category
- Java
- Title
- lopp array java
- Category
- Java
- Title
- long input in JAVA
- Category
- Java
- Title
- a recursive function that calculates the greatest common divisor from user's input in java
- Category
- Java
- Title
- import collections in java
- Category
- Java
- Title
- google translate
- Category
- Java
- Title
- java random number in range
- Category
- Java
- Title
- changing double space to single in java script
- Category
- Java
- Title
- main method java
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- spigot spawn firework
- Category
- Java