terminated javaw error when running eclipse - java

im trying to connect to mysql database and manipulate the data in it but when i try to run my code it get the error, driver [java application] C:\program files\java\jre 1.8.0_111\bin\javaw.exe from what ive been reading its because its launching javaw and not java.exe but i cant seem to figure out how to switch to that can anyone help me?
package jdbc;
import java.sql.*;
public class Driver {
public static void main(String[] args) {
try
{
//get a connection to the database
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cs160test");
//create a statement
Statement myStmt = myConn.createStatement();
//execute the sql query
ResultSet myRs = myStmt.executeQuery("select * from genre");
//process the result set
while(myRs.next())
{
System.out.println(myRs.getString("name"));
}
}
catch(Exception exc)
{
exc.printStackTrace();
}
}
}

That is no error. It is telling you that your program exited because there wasn't further instructions to follow.
<terminated> main [java application] path\bin\javaw.exe
I reproduced this behavior and the only way this is happening is if your genre table has no records.

Ensure that all your classes are saved, including the one with the main method. If that does not work, close Eclipse and reopen it.

Related

Inserting Data into MySQL using Java

I try to insert data into MySQL using Java and I have error all the time.
I use this video to understand how to do to the connection.
This is my Java code:
import java.sql.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null;
//DriverManager.registerDriver(new com.mysql.jdbc.Driver ());
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/try1-progrem", "root", "123456");
Statement st = conn.createStatement();
String username = "kola";
String password = "24688642";
String insert = "INSERT INTO login VALUES ('"+username+"','"+password+"')";
st.executeUpdate(insert);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Get the error:
java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost:3306/try1-progrem
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Main.main(Main.java:11)
And here to SQL image: sql data:
** I learned from YouTube how to make the connection, if there is a good guild, I will glad to take him.
*EDIT1:
build
To fix this you should follow the steps below:
You need to download the correct ConnectorJ from the link below.
After downloading the correct installer for your machine you will need to run the installer to install only the correct jdbc connector for you. (A series of prompts will lead you to selecting the connector and not all the MySQL downloads)
Then you can put the .jar file (connectorJDBC file) into your classpath appropriately and this should fix your problem as I encountered a similar problem while trying to connect to a SQL server with java.
Hopefully this fixes your problem, comment if it doesn't. :)
ConnectorJ Download

java.lang.NoSuchMethodError: org.apache.hive.service.cli.TableSchema

I am trying to connect to hive using Java. This is my code. I am running it in Eclipse Oxygen. My Java version is 8.
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException
{
try
{
Class.forName(driverName);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive2://<ip>:<port>/database", "username", "password");
String sql = "select * from tablename";
Statement stmt = con.createStatement();
stmt.executeQuery(sql);
}
I am able to create table and insert data into table using the above method. But whenever I try to retrieve data from table it throws the following error.
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hive.service.cli.TableSchema.<init>(Lorg/apache/hive/service/cli/thrift/TTableSchema;)
Given below are the jars I am using. They have the classes given in the error.
commons-logging-1.2
curator-client-2.0.0-incubating
hadoop-common-2.7.3
hadoop-common-3.1.0
hive-exec-3.0.0
hive-jdbc-1.1.0
hive-metastore-3.0.0
hive-service-1.1.0
hive-service-3.0.0
hive-service-rpc-2.1.0
httpclient-4.5.6
httpcore-4.4.10
libfb303-0.9.3
libthrift-0.9.3
log4j-1.2.17
slf4j-api-1.8.0-beta2
Please help me.
The error might be caused by incompatible library versions. You have multiple jar versions of the same libs in your project. Therefore at runtime it will not be clear switch one is used.
get rid of the duplicates and use only the newer versions of hadoop-common, hive-service.

JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting

Hello im trying to connect to a mysql database using JDBC my code is below.I get an error as such No suitable driver found.Searching around I found that the usual error is syntax or missing the jar file from the class path.I tried both of these solutions and dont know what to do next it wont connect.Also to manage the databases I have WAMP and mySQL workbench installed not sure if its related.
package test.jdbc;
import java.sql.*;
public class jdbctester {
public static void main(String[] args)
{
try
{
Connection myconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/voting","root","Vanquish123");
Statement myStmt=myconn.createStatement();
ResultSet myRs=myStmt.executeQuery("select * from electoral");
/*
while(myRs.next())
{
System.out.println(myRs.getString("state")+","+myRs.getString("perDem"));
}
*/
}
catch(Exception exc)
{
exc.printStackTrace();
}
}
}
Try this:
Class.forName("fully qualified driver class name");
Java Class.forName, JDBC connection loading driver
this post states that you should not need it but it will not hurt you to try.
you have to add "com.mysql.jdbc_5.1.5.jar" in to your project build path... go to project property>build Path> library> add external jar and add jar file.
Connection conn = null;
try {
// Register JDBC driver
Class.forName(DRIVER).newInstance();
// Open a connection
conn = DriverManager.getConnection(Local_URL + , USERNAME, PASSWORD);
System.out.println("Connected Database Successfully...\n\n");
} catch (Exception se) {
throw new AppException("Failed to create Local Database connection", se);
}
return conn;

Getting "The filename, directory name, or volume label syntax is incorrect" error while connecting to MySQL (wamp server) from JAVA (eclipse)

I have a basic JAVA-MySQL connection class. But, when I execute the code I get
The filename, directory name, or volume label syntax is incorrect
error.
I am using MySQL through wamp server. And, Eclipse is my IDE.
Code (MySQL_connection.java) :
import java.sql.*;
public class MySQL_connection {
public static void main(String args[]) {
try {
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:8080/error_report","root","");
System.out.println("Connection success");
} catch (Exception e) {
System.err.println(e);
}
}
}
I have created error_report database from phpmyadmin.
Check to make sure your MySQL config file does not contain & in the XML. XML Files must use &amp

UCanAccess error: user lacks privilege or object not found

I am trying to manipulate a MS Access database with java without ODBC and I've tried following the instructions over at Manipulating an Access database from Java without ODBC but I keep on getting the error:
Error connecting net.ucanaccess.jdbc.UcanaccessSQLException: user lacks privilege or object not found: EMPLOYEE
I have already added the necessary JAR files to the library so I believe that something is wrong with my code or database. I am fairly new to databases and running Java SE 8 and using the NetBeans IDE 8.0.
The code is below
package javaapplication1;
import java.sql.*;
public class Dbase {
public static void main(String[] args) {
try {
Connection c = DriverManager.getConnection(
"jdbc:ucanaccess://C:/Users/nevik/Desktop/databaseJava/Employee.accdb");
Statement s = c.createStatement();
ResultSet resSet = s.executeQuery("SELECT [FNAME] FROM [Employee]");
while (resSet.next()) {
System.out.println(resSet.getString(1));
}
}
catch (SQLException sqle) {
System.err.println("Error connecting " + sqle);
}
}
}

Categories

Resources