mysql-connector

Insert using PreparedStatement. How do I auto-increment the ID?

橙三吉。 提交于 2019-11-26 20:36:53
问题 I have a PreparedStatement such as: PreparedStatement preparedStatement = connect.prepareStatement("INSERT into employee (id, time, name" + "(?,?,?)",Statement.RETURN_GENERATED_KEYS); ResultSet tableKeys = preparedStatement.getGeneratedKeys(); preparedStatement.executeUpdate(); tableKeys.next(); int autoGeneratedID = tableKeys.getInt(1); preparedStatement.setInt(1,autoGeneratedID); preparedStatement.setTimestamp(2, new java.sql.Timestamp(new java.util.Date().getTime())); preparedStatement

ClassNotFoundException with com.mysql.cj.jdbc.Driver, MySQL Connector and IntelliJ IDEA

那年仲夏 提交于 2019-11-26 18:34:28
问题 I'm building up a Maven Java 1.8 project in which I've included the MySQL Connector as a dependency: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.39</version> </dependency> In my application I've a singleton that holds the MySQL connection so when the application starts, the MySQL connector is triggered but I got a ClassNotFoundException for the driver that I'm using: com.mysql.cj.jdbc.Driver . The JDBC URL that I'm using is: jdbc:mysql:/

Connect to remote MySQL database through SSH using Java

空扰寡人 提交于 2019-11-26 18:28:56
How can I connect to remote MySQL database through SSH from java application? Small code example is helpful for me and I'd appreciate this. My understanding is that you want to access a mysql server running on a remote machine and listening on let's say port 3306 through a SSH tunnel. To create such a tunnel from port 1234 on your local machine to port 3306 on a remote machine using the command line ssh client, you would type the following command from your local machine: ssh -L 1234:localhost:3306 mysql.server.remote To do the same thing from Java, you could use JSch , a Java implementation

Writing to MySQL database with pandas using SQLAlchemy, to_sql

狂风中的少年 提交于 2019-11-26 17:10:16
trying to write pandas dataframe to MySQL table using to_sql. Previously been using flavor='mysql', however it will be depreciated in the future and wanted to start the transition to using SQLAlchemy engine. sample code: import pandas as pd import mysql.connector from sqlalchemy import create_engine engine = create_engine('mysql+mysqlconnector://[user]:[pass]@[host]:[port]/[schema]', echo=False) cnx = engine.raw_connection() data = pd.read_sql('SELECT * FROM sample_table', cnx) data.to_sql(name='sample_table2', con=cnx, if_exists = 'append', index=False) The read works fine but the to_sql has

What&#39;s the difference between MySQLdb, mysqlclient and MySQL connector/Python?

假如想象 提交于 2019-11-26 12:52:57
问题 So I\'ve been trying to do some database update with python and while setting up the whole dev environment, I came across these three things which made me dizzy. There\'s MySQLdb There\'s mysqlclient And then there\'s a mysql connector python What\'s each of them, the difference and where to use them? Thanks 回答1: MySQLdb is a thin python wrapper around C module which implements API for MySQL database. There was MySQLDb1 version of wrapper used some time ago and now it is considered to be a

How do I setup ASP.NET MVC 2 with MySQL?

♀尐吖头ヾ 提交于 2019-11-26 10:15:16
问题 Is it possible to setup ASP.NET MVC 2 to work with a MySQL database? 回答1: I'm assuming that you have Visual Studio Professional 2008, have access to an instance of MySQL server, and have moderate to advanced development experience. This MAY work with VS2008 Web edition, but not at all sure. If you haven't, install MySQL Connector for .NET (6.2.2.0 at the time of this write-up) Optional: install MySQL GUI Tools If you haven't, install MVC 2 RTM, or better yet, use Microsoft's Web Platform

Can&#39;t Create Entity Data Model - using MySql and EF6

若如初见. 提交于 2019-11-26 09:26:13
问题 I\'m trying to add an edmx Entity model to my C#/Web Project in Visual Studio 2013. My problem is that the file is not created. I do the following steps: Give the item a name Choose \'EF Designer from database\' Choose the connection from the drop down (localhost) that already tested successfully connecting to MySQL databse The \"Save connection settings in webc.config as\" option is checked I click \'Next\' AND the window disappeared and I get back to the code window No edmx file is created.

How to connect to a MySQL Data Source in Visual Studio

做~自己de王妃 提交于 2019-11-26 09:09:06
问题 I use the MySQL Connector/Net to connect to my database by referencing the assembly (MySql.Data.dll) and passing in a connection string to MySqlConnection . I like that because I don\'t have to install anything. Is there some way to \"Choose Data Source\" in Visual Studio 2010 without installing something? How can I get a MySQL option (localhost) to show up on one of these lists? Or do I have to install something? (I don\'t want to use ODBC btw) \"Add Connection\" from Server Explorer: Entity

Writing to MySQL database with pandas using SQLAlchemy, to_sql

耗尽温柔 提交于 2019-11-26 06:04:58
问题 trying to write pandas dataframe to MySQL table using to_sql . Previously been using flavor=\'mysql\' , however it will be depreciated in the future and wanted to start the transition to using SQLAlchemy engine. sample code: import pandas as pd import mysql.connector from sqlalchemy import create_engine engine = create_engine(\'mysql+mysqlconnector://[user]:[pass]@[host]:[port]/[schema]\', echo=False) cnx = engine.raw_connection() data = pd.read_sql(\'SELECT * FROM sample_table\', cnx) data

Python MySQL Connector database query with %s fails

让人想犯罪 __ 提交于 2019-11-26 02:10:57
I have a basic program that is supposed to query a database that contains user information. I am trying to select the information for a specific user and print it out to the console. Here is my code: import mysql.connector funcon = mysql.connector.connect(user='root', password='pass', host='127.0.0.1', database='fundata') funcursor = funcon.cursor() query = ("SELECT * FROM funtable WHERE userName=%s") uName = 'user1' funcursor.execute(query, uName) for (userName) in funcursor: print("{}".format(userName)) I have the username stored in a variable because later I plan on getting the user name