I am having trouble finding any documentation on how to write java code to have
ID: 3884692 • Letter: I
Question
I am having trouble finding any documentation on how to write java code to have it access and write SQL to create a table on a server. assignment described below
books used: Java in a Nutshell. By Evans. O’Reilly. 6the Edition & Java Programming 8th Edition Joyce Farrell
ASSIGNMENT:
Create a java class in netbeans utililzing java 8 that will log you into a mysql server.
It should utilize your campus mysql server.(or any mysql server)
The program should utilize sql code to create a table that shows 3 items. X, Y , Z
The table should have 3 records listed on it.
list/show the table
Explanation / Answer
ConnectionClass.java
import java.sql.*;
public class ConnectionClass{
public static void main(String args[]){
try{
//Driver class required for connection to Database
Class.forName("com.mysql.jdbc.Driver");
//Establish Connection
Connection conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/AkshayBisht","root","toor");
//Creating statement for connection in database
Statement st=conn.createStatement();
//Executing query
ResultSet res=st.executeQuery("select X,Y,Z from emp");
while(res.next())
System.out.println(res.getInt(1)+" "+res.getString(2)+" "+res.getString(3));
// Closing Connection
conn.close();
}catch(Exception e){ System.out.println(e);}
}
}//end of Main
Rate an upvote....Thankyou
Hope this helps.....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.