sql query in java

Solutions on MaxInterview for sql query in java by the best coders in the world

showing results for - "sql query in java"
Lisa
11 Jul 2020
1import java.sql.*;
2
3/**
4 * A Java MySQL SELECT statement example.
5 * Demonstrates the use of a SQL SELECT statement against a
6 * MySQL database, called from a Java program.
7 * 
8 * Created by Alvin Alexander, http://alvinalexander.com
9 */
10public class JavaMysqlSelectExample
11{
12
13  public static void main(String[] args)
14  {
15    try
16    {
17      // create our mysql database connection
18      String myDriver = "org.gjt.mm.mysql.Driver";
19      String myUrl = "jdbc:mysql://localhost/test";
20      Class.forName(myDriver);
21      Connection conn = DriverManager.getConnection(myUrl, "root", "");
22      
23      // our SQL SELECT query. 
24      // if you only need a few columns, specify them by name instead of using "*"
25      String query = "SELECT * FROM users";
26
27      // create the java statement
28      Statement st = conn.createStatement();
29      
30      // execute the query, and get a java resultset
31      ResultSet rs = st.executeQuery(query);
32      
33      // iterate through the java resultset
34      while (rs.next())
35      {
36        int id = rs.getInt("id");
37        String firstName = rs.getString("first_name");
38        String lastName = rs.getString("last_name");
39        Date dateCreated = rs.getDate("date_created");
40        boolean isAdmin = rs.getBoolean("is_admin");
41        int numPoints = rs.getInt("num_points");
42        
43        // print the results
44        System.out.format("%s, %s, %s, %s, %s, %s\n", id, firstName, lastName, dateCreated, isAdmin, numPoints);
45      }
46      st.close();
47    }
48    catch (Exception e)
49    {
50      System.err.println("Got an exception! ");
51      System.err.println(e.getMessage());
52    }
53  }
54}
55
Amin
09 Jan 2020
1stmt = con.createStatement();
2
Josué
14 Nov 2017
12, Fred, Flinstone, 2010-06-23, false, 6000
23, Barney, Rubble, 2010-06-23, false, 5000
3
Jevan
04 Sep 2020
1ResultSet rs = stmt.executeQuery(query);
2
queries leading to this page
sql query in javasql java queryhow to get a string from a database in sql in java selectquery string example java database connection and run query javafetch data from mysqljava 40query select in javsjava select jdbcjava select all from databasejdbc queryfind data in sql on javajdbc query in javawriting sql queries in javaselect data into table java mysqlfetch data from mysql table javaquery java exemple javajava query examplejdbc example select fromuse sql query in javasql java query 25sjava mysqlp where queryjava sql query examplejava read from databasesql query javamysql get data from table javajava get data from mysqljava send custom sql commands to dbhow to write a sql statement in javaselect data into table java mydqljava mysql select data in rowsql statement java example likejava mysql findselect 2a from table sql javaread data from mysql database using javajava program to fetch data from mysql databasesleect stament java jdbcjava query mysqljava jdbc sql queryjava select query wheresql queries javajdbc query with 3dselect id from company where name 3d 3f in java mysqlhow to execute mysql query in javahow to fetch data from mysql database in javajava how to query sqljdbc queries in javajdbc run querysql queries in javajava statement selectgrab varchar from sql in javahow to create queries in javahow to write sql query in javagrab data from mysql javahow to execute show database query in javajava progra to execute sql queresjava jdbc queryjava mysql selecthow to make select in javaselect in sql in javahow to use sql in javahow to write sql queries in javahow to read from database in javahow to make sql query via javajdbc query one lineselect 2afrom sql where javaget the sql code from query javajava mysql select queryjava simple sql queryget data from mysql javajava connect to mysql selecthow to fetch values from mysql db with javahow to print response of sql select query in javaselect values database jvajava sql query in statementmysql java selectselect jdbc javahow to get query from sql statement javajdbc select statementjava mysql execute queryjdbc query with 3fjava mysql select query exampleselect jdbc sqlseql calls in javahow do i querie in javaselect query in jdbcselect 2a from 28select 3f 2c 3f 29 in java sqlhow should you make queries to sql in javadisplay database values in java using mysql connector selectjava class to fetch data fro mysql databasejava make a sql requestjava mysql select lisrtjava queriesjava mysql queryjava how to sql queryshow java sql queryjava read data from mysqlwriting select statements in javaselect query with jdbc javaoutput results of sql select javause database and select java mysqlsql in javajava sql query with 3c 3ehow to get all data from a database in javawhat are queries in javamysql java select queryjava code sql querygrab all mysql java 3c 3e 3f sql java querywrite sql query javasql query in statement javahow to write query in javajava sql queryexecute sql query to get users in database javamysql query javajdbc oracle select examplejava select from where mysqlmaking sql queries in javaselect statement sql javahow to read data from mysql table using javajdbc make queryhow to query mysql in javahow to use select sql in javasql get data javacall a sql statement in javajava sql select fromexecutequery db query in javajava get string from mysql java sql select statementsql queries java codeselect sql javajava sts print query resultfind query in jdbcjava mysql read tablesql seaech in javasql query in java