Question

is it possible to create a sql file and java file on same platform on eclipse...

is it possible to create a sql file and java file on same platform on eclipse or net beans and connect without using local host and password etc connection

0 0
Add a comment Improve this question Transcribed image text
Answer #1

To connect Java application with the MySQL database, Driver class, Connection URL, Username, Password are necessary to establish the connection. The connection statement would be :

Connection con = DriverManager.getConnection("jdbc:mysql://servername/ipaddress:port_number/database_name",username,password);

Here, jdbc is the API, mysql is the database. In the servername you can use localhost or the ip address where mysql is running. But it is necessary to establish a connection between the java code and the required database to execute the DDL or DML or DCL statements in the application.

The sample example would be given below.

import java.sql.*;
class Mysql_connection{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://10.212.30.116:2443/ECE",root,Password1234);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from Application");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2));
con.close();
}
catch(Exception e){
System.out.println(e);
}
}
}

Add a comment
Know the answer?
Add Answer to:
is it possible to create a sql file and java file on same platform on eclipse...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java(Eclipse). The task will create a server and client and send a message from the client...

    Java(Eclipse). The task will create a server and client and send a message from the client to the server. We will have two classes NetworkClient and NetworkServerListener classes. These will each have a main to run from the command line The NetworkServerListener class will listen for a client connection from NetworkClient , receive a message, display the message to the console (stdout) and exit. The NetworkClient class will create a connection to the NetworkServerListener and send a message to the...

  • Python3 create a text file that contains 25 possible passwords read a file and make it...

    Python3 create a text file that contains 25 possible passwords read a file and make it to list of passwords by list comprehension format the output by creating a function called show_list Find the password that has same letter twice in a row Find password contains at least 1 letter Find password doesn't start with a vowel, but second character is a vowel find password has twice more not-vowel letters than vowels password doesn't start with a vowel, but second...

  • JAVA sql Code an sql file that creates a 'Contractors' table. See the exercise below for...

    JAVA sql Code an sql file that creates a 'Contractors' table. See the exercise below for an example. Give your 'Contractors' table the following fields Id (integer, primary key) CompanyName (varchar, 30 characters) Phone(varchar, 12 characters) ContactName(varchar, 30 characters) Rating (integer) OutOfStateService (boolean) Also have the sql file create at least five records for the "Contractors" table. Example record: 1, Tom's Contracting, 555-555-5555, Tom Thumb, 81, true import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class TestDB...

  • Write a Java program in Eclipse that reads from a file, does some clean up, and...

    Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...

  • Java Language Create file fports with the first line as a hostname that needs to be...

    Java Language Create file fports with the first line as a hostname that needs to be scanned for certain ports to be opened on it (the values shown are examples... you need to select your own values): host name 80 22 443 445 Write a java program to accomplish the following: Open file fports Read the hostname to be scanned and store it in variable hostname Read the ports into array of integers ports Create array status (of boolean type)...

  • Can you please upload the video to step by step with eclipse and mysql workbench.please.............

    Can you please upload the video to step by step with eclipse and mysql workbench.please................................ Part 1 Design the database using the ER approach. Then using Java and SQL, implement the following functionality: 1. Implement a button called “Initialize Database” . When a user clicks it, all necessary tables will be created (or recreated) automatically, with each table be populated with at least 10 tuples so that each query below will return some results. All students should use the database...

  • Can you please upload the video to step by step with eclipse and mysql workbench.please................................ Part...

    Can you please upload the video to step by step with eclipse and mysql workbench.please................................ Part 1 Design the database using the ER approach. Then using Java and SQL, implement the following functionality: 1. Implement a button called “Initialize Database” . When a user clicks it, all necessary tables will be created (or recreated) automatically, with each table be populated with at least 10 tuples so that each query below will return some results. All students should use the database...

  • Put all of your SQL code in a file named grades.sql and submit it below. Download...

    Put all of your SQL code in a file named grades.sql and submit it below. Download the starter code, which contains import_grades.sql and the grades.csv file. Using he import_grades, sql file, create your database and table. - 0 eded. 1 T Une Modify the LOAD DATA INFILE to correct the path to load the grades.csv file, and add/remove LOCAL he only modification you may make to the import_grades.sql or the grades.csv files. The data represents grades for assignments in a...

  • This is a java program that runs on the Eclipse. Java Programming 2-1: Java Class Design...

    This is a java program that runs on the Eclipse. Java Programming 2-1: Java Class Design Interfaces Practice Activities Lesson objectives: Model business problems using Java classes Make classes immutable User Interfaces Vocabulary: Identify the vocabulary word for each definition below. A specialized method that creates an instance of a class. A keyword that qualifies a variable as a constant and prevents a method from being overridden in a subclass. A class that it can't be overridden by a subclass,...

  • Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file...

    Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT