import java.beans.Statement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.JOptionPane;

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 3RP
icon
Related questions
Question

Can someone help what is the reason of ERROR in 39th line and 43rd line?

search from database

1
String department
Cment") 7
JOptionPane.showMessageDialog(null, "Name:" + name + "\nAGE: " + age + "\nPOSITION: " + position + "\nDEPARTMENT: " + department, "SEARCH FROM DATABASE", JOptionPane. INFORMATION_MESSAGE) ;
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally{
try{
if (stmt!=null)
stmt.close();
}catch (SQLException se2) {
}
try{
if (conn!=null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Thank you.", SEARCH FROM DATABASE", JOptionPane. INFORMATION_MESSAGE) ;
}
Transcribed Image Text:1 String department Cment") 7 JOptionPane.showMessageDialog(null, "Name:" + name + "\nAGE: " + age + "\nPOSITION: " + position + "\nDEPARTMENT: " + department, "SEARCH FROM DATABASE", JOptionPane. INFORMATION_MESSAGE) ; } rs.close(); stmt.close(); conn.close(); } catch (SQLException se) { se.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally{ try{ if (stmt!=null) stmt.close(); }catch (SQLException se2) { } try{ if (conn!=null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } JOptionPane.showMessageDialog(null, "Thank you.", SEARCH FROM DATABASE", JOptionPane. INFORMATION_MESSAGE) ; }
4
* and open the template in the editor.
5
package mysqlsearch;
7
8
import java.beans. Statement;
9 import java.sql.Connection;
10
import java.sql.DriverManager;
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13
import javax.swing.JOptionPane;
14
15
/**
16
*
17
* @author kell_pc
18
*/
19
public class MySqlSearch {
20
21
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
22
23
static final String DB_URL = "jdbc:mysql://localhost/sanagustin_database";
24
25
static final String USER = "root";
26
static final String PASS = "";
27
28
public static void main(String[] args) {
29
Connection conn = null;
30
Statement stmt = null;
31
String searchName= JOptionPane.show Input Dialog(null, "Select the name or first letter of the name");
try{
32
33
Class. forName ("com.mysql.jdbc.Driver");
34
35
System.out.println("Connecting to database...");
36
conn = DriverManager.getConnection (DB_URL, USER, PASS);
37
38
System.out.println("Creating statement...");
stmt = conn.createStatement ();
40
String sql;
41
42
;
sql = "SELECT name, age, position, department FROM tblinfol WHERE name LIKE'"+searchName+"""
ResultSet rs = stmt.executeQuery (sql);
44
45
while (rs.next()) {
46
47
String name = rs.getString ("name");
48
int age = rs.getInt ("age");
49
String position = rs.getString("position");
50
String department = rs.getString ("department");
51
Transcribed Image Text:4 * and open the template in the editor. 5 package mysqlsearch; 7 8 import java.beans. Statement; 9 import java.sql.Connection; 10 import java.sql.DriverManager; 11 import java.sql.ResultSet; 12 import java.sql.SQLException; 13 import javax.swing.JOptionPane; 14 15 /** 16 * 17 * @author kell_pc 18 */ 19 public class MySqlSearch { 20 21 static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; 22 23 static final String DB_URL = "jdbc:mysql://localhost/sanagustin_database"; 24 25 static final String USER = "root"; 26 static final String PASS = ""; 27 28 public static void main(String[] args) { 29 Connection conn = null; 30 Statement stmt = null; 31 String searchName= JOptionPane.show Input Dialog(null, "Select the name or first letter of the name"); try{ 32 33 Class. forName ("com.mysql.jdbc.Driver"); 34 35 System.out.println("Connecting to database..."); 36 conn = DriverManager.getConnection (DB_URL, USER, PASS); 37 38 System.out.println("Creating statement..."); stmt = conn.createStatement (); 40 String sql; 41 42 ; sql = "SELECT name, age, position, department FROM tblinfol WHERE name LIKE'"+searchName+""" ResultSet rs = stmt.executeQuery (sql); 44 45 while (rs.next()) { 46 47 String name = rs.getString ("name"); 48 int age = rs.getInt ("age"); 49 String position = rs.getString("position"); 50 String department = rs.getString ("department"); 51
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Procedures in SQL
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning