import java.beans.Statement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.JOptionPane;
import java.beans.Statement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.JOptionPane;
Chapter3: Data Representation
Section: Chapter Questions
Problem 3RP
Related questions
Question
Can someone help what is the reason of ERROR in 39th line and 43rd line?
search from
![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) ;
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fce01bb58-0e02-419d-811c-f275c38fab0f%2Fa3e00ba5-7282-42bf-ab41-5667e8d8c540%2Fefnax3_processed.png&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fce01bb58-0e02-419d-811c-f275c38fab0f%2Fa3e00ba5-7282-42bf-ab41-5667e8d8c540%2Fp527kwk_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning